9

I can't seem to be able to evaluate Java code snippets in org mode. Here is what I have

#+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 evalute python blocks just find though. The same java snippet works fine if I compile it with javac.

I have already enabled java in the emacs init file.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user3146687
  • 389
  • 1
  • 3
  • 11

2 Answers2

11

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
user3146687
  • 389
  • 1
  • 3
  • 11
2

You need to include :classname Test, like this

#+BEGIN_SRC java :classname Test
class Test {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}
#+END_SRC
Matt Curtis
  • 23,168
  • 8
  • 60
  • 63
Tanis
  • 31
  • 1