ant javac task使用哪个javac.exe?

Com*_*Man 3 java ant compilation javac

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

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

Gui*_*let 6

实际上,我相信,默认情况下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);
        }
    }
Run Code Online (Sandbox Code Playgroud)

代码来自这里.

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

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