JavaXT

Compiler Class

Dynamic, in-memory, Java compiler. Sample usage:
        StringBuilder src = new StringBuilder();
        src.append("public class MyClass {\n");
        src.append("    public String toString() {\n");
        src.append("        return \"Hello, Peter I am \" + ");
        src.append("this.getClass().getSimpleName();\n");
        src.append("    }\n");
        src.append("}\n");        

        Class _class = Compiler.compile("MyClass", src.toString());
        Object instance = _class.newInstance();
        System.out.println(instance);
 
Original source code can be found here:
http://www.javablogging.com/dynamic-in-memory-compilation/

Constructors

public Compiler( )

Methods

compile( String className, String src ) returns Class
Used to compile a block of code.
classNameFull name of the class that will be compiled. If class should be in some package, className should contain it too (ex. "com.example.MyClass")
srcSource code.