现象:
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
public class Demo01 {
public static void main(String[] args) throws Exception {
JavaCompiler compiler = ToolProvider.getSystem;
int result =compiler.run(null,null,null,"d:/my;
System.out.println(result);
}
}
run上面出现错误下划线,鼠标查看报错。
报错内容:
The method run(InputStream, OutputStream, OutputStream, String[]) in the type Tool is not applicable for the arguments (null, null, null, String)。
解决方法
这里我问题是JDK的版本问题,当前项目的JDK版本为1.4。
右键当前项目,Build Path->Configure Build Path->左侧Java Compilre里选择JDK版本为1.8。(并没有测试其他版本。)