Run Java code in org mode

I cannot describe fragments of Java code in org mode. That's what i

#+BEGIN_SRC java public class Main { public static void main(String[] args) { System.out.println("hello world"); } } #+END_SRC 

I get the following error: can't compile a java block without a classname . I can verify that python blocks just find. The same java fragment works fine if I compile it using javac.

I already included java in the init emacs file.

+6
source share
2 answers

I should have done more googling, found the answer here: http://ehneilsen.net/notebook/orgExamples/org-examples.html

 #+HEADERS: :classname HelloWorld #+begin_src java :results output :exports both public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } } #+end_src #+RESULTS: : Hello, World 
+5
source

You need to include :classname Test , e.g.

 #+BEGIN_SRC java :classname Test class Test { public static void main(String[] args) { System.out.println("Hello world!"); } } #+END_SRC 
0
source

Source: https://habr.com/ru/post/1013850/


All Articles