0
MyClass.java:
package test;
public class MyClass {
public void myMethod(){
System.out.println("My Method Called");
}
}
Listing for SimpleCompileTest.java that compiles the MyClass.java file.
SimpleCompileTest.java:
package test;
import javax.tools.*;
public class SimpleCompileTest {
public static void main(String[] args) {
String fileToCompile = "test" + java.io.File.separator +"MyClass.java";
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); //Line 6
int compilationResult = compiler.run(null, null, null, fileToCompile);
if(compilationResult == 0){
System.out.println("Compilation is successful");
}else{
System.out.println("Compilation Failed");
}
}
}
ERROR使用Java API來編寫
我編譯SimpleCompileTest.java和收到此錯誤。幫幫我!!!
你試過調試過嗎?您也可以提供代碼行號 - 堆棧跟蹤指向第6行。 – LastFreeNickname
@LastFreeNickname完成 – rick
可能的重複http://stackoverflow.com/questions/15513330/toolprovider-getsystemjavacompiler-returns-null-usable-with- only-jre-install –