Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


The SimpleCompiler compiles a single "compilation unit" (a.k.a. ".java" file). Opposed to to normal JavaTM compilation, that compilation unit may define more than one public class. Example:

Code Block
// File "mycode.janino".

package my.pkg;

import java.util.*;

public class A {
    public static void main(String[] args) {
        B b = new B();

public class B {
    void meth1() {
        System.out.println("Hello there.");

It returns a ClassLoader from which you can retrieve the classes that were compiled.

To run this, type:

Code Block
$ java org.codehaus.janino.SimpleCompiler -help
    org.codehaus.janino.SimpleCompiler <source-file> <class-name> { <argument> }
Reads a compilation unit from the given <source-file> and invokes method
"public static void main(String[])" of class <class-name>, passing the
given <argument>s.
Code Block
$ java org.codehaus.janino.SimpleCompiler mycode.janino my.pkg.A
Hello there.