Table Of Contents

Previous topic

jannotation – Jython annotations

Next topic

junit – Annotations for JUnit 4.X

This Page

jcompile – Java 6 Compiler API Wrapper

The jcompile module implements the class JavaCompiler used to compile Java sources at runtime. It relies on the Java Compiler API specified in JSR 199.

Classes

Changed in version 0.3: JavaCompiler keyword arguments remove and todisk were removed.

class jcompile.JavaCompiler(processors = None[, store = False])
Parameters:
  • processors – list of annotation processors that will be invoked by the javac compiler.
  • store – when store is True the generated Java bytecode will be saved and stored in a class file at org/jynx/gen.
  • remove – when remove is True the class file will be deleted after the Java bytecode is loaded.
createClass(className, codeStr, *flags)
Parameters:
  • className – the name of the Java class that shall be created. The name must coincide with the class name in the source code.
  • codeStr – the Java source code.
  • flags – compiler flags specified for javac.
Returns:

new Java class imported into Jython.

createAnnotation(annotationName, codeStr, *flags)
Parameters:
  • annotationName – the name of the Java annotatiom that shall be created. The name must coincide with the annotation name in the source code.
  • codeStr – the Java annotation code.
  • flags – compiler flags specified for javac.
Returns:

new Java annotation imported into Jython.

Examples:

codeStr = '''
public class %s {
    public static void main(String args[])
    {
        System.out.println("Hello "+args[0]);
    }
}'''

Foo = JavaCompiler().createClass("Foo", codeStr%"Foo")

Foo.main(["Jython!"])