[英]Which javac.exe is used by ant javac task?
我面臨一個問題。 我在我的機器上重命名了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
,它可能指向其他位置
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.