Which javac.exe is used by ant javac task?

烈酒焚心 提交于 2019-12-01 22:29:45

问题


I am facing one problem. I renamed javac.exe on my machine and noticed that ant javac task still works fine.

Does anybody know from where its getting javac.exe?


回答1:


Actually, I believe, that by default Ant tries to execute the java compiler class directly with this code:

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);
        }
    }

The code came from here.

Which means that if the library tools.jar is on the current classpath of Ant, it will pickup the class and launch it. This results in the fact that javac.exe can be renamed to whatever you want, it will still work. So to answer your question, it actually executes none of any "javac.exe".

There are other implementations of the Javac task, but I think this is the default one for all compilers 1.3+




回答2:


You could try starting here and check what is configured in global build.compiler property, it may be pointing somewhere else



来源:https://stackoverflow.com/questions/10543336/which-javac-exe-is-used-by-ant-javac-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!