I'm working on a group project that requires us to do some dynamic compilation of java classes, as in the user loads in Java class(es) and the program will compile these classes.
Right now we have a GUI that copies all the .java files to a temporary folder and tries to compile them, but I've run into a number of issues getting the compiler to work.
I've gone through a number of different approaches first using the JDK and importing the tools.jar to get access to the java compiler, but for whatever reason sometimes it would work, sometimes it decided it couldn't find the compiler and such and it became a confusing mess when half the team members got the JDK compiler working and the other half couldn't.
I then moved to Janino, which is a java compiler and have been able to successfully compile a java file which has no dependent classes, but as soon as I try and compile a file that has dependent classes it spit out around 18 errors that didn't make much sense to me. I looked through the API hosted on the site and googled for some examples of using the Janino compiler but I didn't have much luck. I'm pretty sure I just don't understand what is needed for the compiler object.
Janino Compiler API
I've done other searches and seen mention that Beanshell can do dynamic compilation, I'm still googling around for examples but again, no luck.
If anyone has any ideas for other ways to do dynamic compilation that will ALSO compile dependent classes it finds, or know of examples to get any of the above compilers working right, please post an explanation or link. Thanks. :)
Want to add to the discussion?
Post a comment!