ant javac 任务使用了哪个 javac.exe? [英] Which javac.exe is used by ant javac task?

查看:32
本文介绍了ant javac 任务使用了哪个 javac.exe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

有谁知道它从哪里得到 javac.exe?

Does anybody know from where its getting javac.exe?

推荐答案

实际上,我相信,默认情况下 Ant 会尝试使用以下代码直接执行 java 编译器类:

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

代码来自这里.

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

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".

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

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

这篇关于ant javac 任务使用了哪个 javac.exe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆