I found and modified the code below to programmatically compile a Java class:
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
public class CompileHello {
public static void main(String[] args) {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
int result = compiler.run(null, null , null , "C:\\Users\\quickCoder\\Desktop\\Hello.java");
System.out.println("Compile result code = " + result);
}
}
However, I keep getting the following error:
Exception in thread "main" java.lang.NullPointerException
at CompileHello.main(CompileHello.java:8)
Line 8
is the following line:
int result = compiler.run(null, null , null , "C:\\Users\\quickCoder\\Desktop\\Hello.java");
I made sure the file path entered is the actual path the Java class I have written.