* Babel: command line args in java
@ 2019-11-05 15:21 Jarmo Hurri
2022-10-20 3:02 ` Ihor Radchenko
0 siblings, 1 reply; 2+ messages in thread
From: Jarmo Hurri @ 2019-11-05 15:21 UTC (permalink / raw)
To: emacs-orgmode
* 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~ ?
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Babel: command line args in java
2019-11-05 15:21 Babel: command line args in java Jarmo Hurri
@ 2022-10-20 3:02 ` Ihor Radchenko
0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2022-10-20 3:02 UTC (permalink / raw)
To: Jarmo Hurri; +Cc: emacs-orgmode
Jarmo Hurri <jarmo.hurri@iki.fi> writes:
> 3. If this is desired behaviour, can I write a patch adding a new
> header argument such as ~cmdargs~ ?
For record, we do support :cmdargs header arg in ob-java.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-20 3:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-05 15:21 Babel: command line args in java Jarmo Hurri
2022-10-20 3:02 ` Ihor Radchenko
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).