我正面临着一个问题。我在我的机器上重命名了javac.exe,并注意到ant javac任务仍然工作良好。
有人知道javac.exe是从哪里来的吗?
发布于 2012-05-11 07:30:30
实际上,我相信,在默认情况下,Ant会尝试使用以下代码直接执行java编译器类:
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);
}
}代码来自here。
这意味着如果库tools.jar位于Ant的当前类路径上,它将获取类并启动它。这导致javac.exe可以重命名为您想要的任何名称,但它仍然可以工作。所以回答你的问题,它实际上不执行任何"javac.exe“。
Javac任务还有其他实现,但我认为这是所有编译器1.3+的默认实现
发布于 2012-05-11 07:22:30
您可以尝试启动here并检查全局build.compiler属性中的配置,它可能指向其他位置
https://stackoverflow.com/questions/10543336
复制相似问题