运行此代码以编译此目录中的 .java 文件时:
String title = txtName.getText();
String name = title + ".Java";
String src = Minecraft.getMinecraft().mcDataDir.getParent().toString() + "/saves/" + world.getWorldInfo().getWorldName().toString() + "/TechRev/Compiler/";
compile(src + name);
使用这种方法:
public void compile(String file) {
String fileToCompile = file;
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
int compilationResult = compiler.run(null, null, null, fileToCompile);
if (compilationResult == 0) {
System.out.println("Compilation is successful");
} else {
System.out.println("Compilation Failed");
}
}
我在 Eclipse Juno(Java 6) 的控制台中收到此错误:
2013-10-02 20:47:47 [INFO] [STDERR] javac: invalid flag: /Users/marko5049/Desktop/Modding/forge/mcp/jars/saves/TechRev/TechRev/Compiler/TechRev.Java
2013-10-02 20:47:47 [INFO] [STDERR] Usage: javac <options> <source files>
2013-10-02 20:47:47 [INFO] [STDERR] use -help for a list of possible options
2013-10-02 20:47:47 [INFO] [STDOUT] Compilation Failed
请有人向我解释为什么会发生这种情况并告诉我如何解决这个问题?谢谢!
-问候马克