Wednesday, December 12, 2007

Progammatically Compile Java Code

I had planned on writing a summary of how to compile Java code programmatically using the javax.tools package in Java 6, but this article pretty much sums up everything I would have said. In short this would allow you to store source or "source strings" in a database or file system and compile them without "shelling out" and utilizing a specific javac. I had been thinking about using javax.script packages to accomplish a dynamic code goal on one of my projects, but I think I'll also use this approach and let the "end user" decide which extension point they would like to utilize. The javax.tools approach would allow significant performance gains due to having compiled code which would take advantage of all the JRE optimizations (i.e. JIT). I need to look into the javax.script implementations to see if a similar compilation is possible or if scripted code remains interpreted forever.

No comments: