Just out of curiosity. Can we compile & run a java file from another java program? If so, can you send a reference to that knowledge source?
Compile another java file from java file
762 views Asked by Reddy At
7
There are 7 answers
0
On
If you're using Java 6, the best way to do this is through the javax.tools.JavaCompiler interface.
If you're using an older version of Java, you must call javac directly using Runtime.exec(), then load the class data by subclassing ClassLoader and overriding findClass.
0
On
Yes, you can, but you need java compiler and not only java runtime. First you generate your source, save it and then use Dynamic class loading(tutorial http://tutorials.jenkov.com/java-reflection/dynamic-class-loading-reloading.html)
Take a look at Java Compiler Api and this little example.