Java compiler API, compiling made easy
1,889 views Before Java 1.6 was released to the public I used the Runtime class (found in java.lang) to call the java compiler (javac.exe) directly to compile a Java file from another Java application, the line of code that i used looks like this
-
Runtime.getRuntime().exec("C:\\WINDOWS\\system32\\cmd.exe /c start javac " + userDir + "\\test\\"+className + ".java");
But luckily for me Java 1.6 introduced a handy utility that makes it possible to compile a Java application within a Java application without making direct calls to an external application. To demonstrate that I wrote a HelloWorld Java file and a CompilerConsoleDemo class that compiles the HelloWorld java file.


(3 votes, average: 3.33 out of 5)



