Possible Duplicate:
Compiling external .java files from within Java
I have been using examples from all over the net but I keep getting NullPointerExceptions when invoking the run method in JavaCompiler. If you know how to compile another java file from within a java file please provide code on how to do this. Thanks
From the documentation for the STBC (which uses the
JavaCompiler
).It will be
null
if the code is run in a non SDK JRE (see explanation in the System Requirements).I already used JavaCompiler to compile math expressions on the fly.
Here is how I did it:
You can use eclipse jdt compiler (http://www.eclipse.org/jdt/core). It is used in many projects to compile java.
Here is an example how tomcat uses it to compile servlets to .class: http://www.docjar.com/html/api/org/apache/jasper/compiler/JDTCompiler.java.html