I am in the process of writing a rule engine that performs simple assignments as determined by conditional constructs. It is a prerequisite of the project that the rules be in XML format. I have modeled my XML schema to resemble simple code blocks. I wish to parse the XML and to then transform it into Java code. I then wish to compile (and run) this code at runtime. Doing so would mean that my rule engine no longer acts as an interpreter but executes native Java Byte Code.

I have figured out the parsing stage and more or less the Java code generation phase. I would now like to figure out the last phase - the compile at runtime phase.

Following this thread: [Compile to java bytecode (without using Java)](https://stackoverflow.com/questions/688098/compile-to-java-bytecode-without-using-java) I have become aware of the following possible solutions:

* [ASM](http://asm.objectweb.org/)
* [BCEL](http://jakarta.apache.org/bcel/)
* [Trove](http://teatrove.sourceforge.net/trove.html)

I would love a comparison of these as well as other suggestions for solving the Java compile at runtime phase.
['https://Stackoverflow.com/questions/1064259', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/101715/']
Javassist is almost a full Java compiler written in Java, and it's completely made of Java. You can't give it a whole .java file at once, but you can give it the code string for individual functions and add them to the same CtClass object, which becomes bytecode and then a java.lang.Class.

I just released version 0.1 of GigaLineCompile, which uses Javassist (compiler) and Beanshell (interpreter) together and gives you control over which code to optimize and when. In later versions, it will change between Javassist and Beanshell at a smaller granularity so if you have many strings of code that share some substrings, the substrings will be compiled and the other parts run in beanshell. Its mostly useful for artificial intelligence that generates Java code, but its also an alternative to Clojure or the extremes of Javassist/Beanshell alone.

Javassist, Beanshell, and GigaLineCompile can be downloaded (with source) here:
<http://sourceforge.net/projects/gigalinecompile>
you can fork a process like this

```
Process p = Runtime.getRuntime().exec("java -classpath "..." SomeClassContainingMain ...other arguments);       

        //you need to consume the outputs of the command if output/error is large otherwise the process is going to hang if output/error buffer is full. and create a seperate thead for it (not created here).
        log.debug("PROCESS outputstream : " + p.getInputStream() );
        log.debug("PROCESS errorstream : " + p.getErrorStream());           
    p.waitFor(); // Wait till the process is finished

```

and can compile and run it.