我遇到了一个问题。我在我的电脑上重命名了javac.exe
,但是发现ant的javac
任务仍然可以正常工作。
有人知道它是从哪里获取javac.exe
的吗?
我遇到了一个问题。我在我的电脑上重命名了javac.exe
,但是发现ant的javac
任务仍然可以正常工作。
有人知道它是从哪里获取javac.exe
的吗?
try {
Class c = Class.forName ("com.sun.tools.javac.Main");
Object compiler = c.newInstance ();
Method compile = c.getMethod ("compile",
new Class [] {(new String [] {}).getClass ()});
int result = ((Integer) compile.invoke
(compiler, new Object[] {cmd.getArguments()}))
.intValue ();
return (result == MODERN_COMPILER_SUCCESS);
} catch (Exception ex) {
if (ex instanceof BuildException) {
throw (BuildException) ex;
} else {
throw new BuildException("Error starting modern compiler",
ex, location);
}
}
这段代码来自这里。
也就是说,如果Ant的当前类路径上有库tools.jar,它将会检索到该类并启动它。这意味着javac.exe可以被重命名为任何你想要的名称,它仍然能够正常工作。因此,回答你的问题,实际上没有执行任何一个"javac.exe"。
还有其他的Javac任务实现,但我认为这是所有编译器1.3+的默认实现。