Sample code to programmatically compile a Java program.
1. public class CompilerExample {
2. public static void main(String[] args) {
3. String fileToCompile = "c:" + java.io.File.separator
4. + "HelloWorld.java";
5. JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
6. int compilationResult = compiler.run(null, null, null, fileToCompile);
7. if (compilationResult == 0) {
8. System.out.println("Compilation is successful");
9. } else {
10. System.out.println("Compilation Failed");
11. }
12. }
13. }
0 comments:
Post a Comment