ant javac task使用哪个javac.exe?

我面临一个问题。 我在我的机器上重命名了javac.exe并注意到ant javac任务仍然正常。

有谁知道它从哪里获取javac.exe?

实际上,我相信,默认情况下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); } } 

代码来自这里 。

这意味着如果库tools.jar位于Ant的当前类路径中,它将拾取类并启动它。 这导致javac.exe可以重命名为你想要的任何东西,它仍然可以工作。 所以要回答你的问题,它实际上不执行任何“javac.exe”。

还有Javac任务的其他实现,但我认为这是所有编译器1.3+的默认实现

您可以尝试从这里开始并检查全局build.compiler属性中配置的build.compiler ,它可能指向其他位置