From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jarmo Hurri Subject: Babel: command line args in java Date: Tue, 05 Nov 2019 17:21:51 +0200 Message-ID: <87imnypcvk.fsf@iki.fi> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:36789) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iS0eg-0003gM-B1 for emacs-orgmode@gnu.org; Tue, 05 Nov 2019 10:22:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iS0ef-0000bl-8I for emacs-orgmode@gnu.org; Tue, 05 Nov 2019 10:22:02 -0500 Received: from 195-159-176-226.customer.powertech.no ([195.159.176.226]:58500 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iS0ef-0000bG-1N for emacs-orgmode@gnu.org; Tue, 05 Nov 2019 10:22:01 -0500 Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1iS0eb-000sqL-1B for emacs-orgmode@gnu.org; Tue, 05 Nov 2019 16:21:57 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org * Intro I am trying to supply command line arguments to java code in babel. For this a logical option would be to use ~:cmdline~ header argument, but I can not get it to work. I really need to process the given values as command line arguments, so setting some variable values will not work. * This does not work Because ~ob-java.el~ concatenates ~:cmdline~ before ~:classname~ , the straightforward way fails. #+begin_src java :classname ArgumentExample :cmdline hi there org fans :results output verbatim class ArgumentExample { public static void main (String[] args) { for (String s : args) System.out.println (s); } } #+end_src #+RESULTS: The results is #+begin_center Error: Could not find or load main class hi Caused by: java.lang.ClassNotFoundException: hi #+end_center The reason is this piece of code in ~ob-java.el~ #+begin_src elisp (org-babel-eval (concat org-babel-java-command " " cmdline " " classname) "") #+end_src * This compiles and runs but not as desired The second try is to provide classname as the first argument. But a ~:classname~ header is also required, so the end result is not the desired one. #+begin_src java :classname ArgumentExample :cmdline ArgumentExample hi there org fans :results output verbatim class ArgumentExample { public static void main (String[] args) { for (String s : args) System.out.println (s); } } #+end_src #+RESULTS: : hi : there : org : fans : ArgumentExample * This fix does not work either When I try to leave out ~:classname~ , the process fails in early stages. #+begin_src java :cmdline ArgumentExample hi there org fans :results output verbatim class ArgumentExample { public static void main (String[] args) { for (String s : args) System.out.println (s); } } #+end_src #+begin_center org-babel-execute:java: Can’t compile a java block without a classname #+end_center * Questions 1. Is there a correct way of doing this already? 2. If there is no better way, is this desired behaviour or should it be fixed? 3. If this is desired behaviour, can I write a patch adding a new header argument such as ~cmdargs~ ?