[英]Ant build not working: unable to find a javac compiler
我正在嘗試運行一些Java EE示例。 Ant建議: Perhaps JAVA_HOME does not point to the JDK. It is currently set to "C:\\Program Files\\Java\\jre7
Perhaps JAVA_HOME does not point to the JDK. It is currently set to "C:\\Program Files\\Java\\jre7
當我查看我的Windows 7變量時,我的JAVA_HOME
變量是: C:\\Program Files\\Java\\jdk1.7.0_03
但是,我的路徑是(注意jdk1.6.0_26):
%M2_HOME%\bin;%ANT_HOME%\bin;%JAVA_HOME%\bin;%SystemRoot%\system32;%SystemRoot%;
%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
C:\Program Files\Microsoft Application Virtualization Client;%M2%;
C:\Program Files\QuickTime\QTSystem\;C:\Program Files\TortoiseSVN\bin;
%GLASSFISH%;%GLASSFISH_PARENT%;
PATH=C:\Maven\apache-maven-2.2.1\bin;C:\Ant\apache-ant-1.8.2\bin;**C:\Program File
s\Java\jdk1.6.0_26\bin;**C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C
:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft Applicatio
n Virtualization Client;C:\Maven\apache-maven-2.2.1\bin;C:\Program Files\QuickTi
me\QTSystem\;C:\Program Files\TortoiseSVN\bin;C:\glassfish3\glassfish\bin;C:\gla
ssfish3\bin;C:\Sun\jwsdp-2.0\jwsdp-shared\bin
我是否必須做一些特別的事情才能讓窗戶保存我的路徑?
更多信息:
C:\javaeetutorial5\examples\web\hello2>ant
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre7\li
b\tools.jar
Buildfile: C:\javaeetutorial5\examples\web\hello2\build.xml
-pre-init:
init:
default-ear:
-pre-compile:
bpp-actual-compilation:
[echo] Compiling hello2
[echo] javaee.classpath.prefix is: C:\glassfish3/lib
[echo] is.glassfish.v3 is: ${is.glassfish.v3}
[javac] C:\javaeetutorial5\examples\bp-project\command-line-ant-tasks.xml:93
: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=las
t; set to false for repeatable builds
BUILD FAILED
C:\javaeetutorial5\examples\bp-project\command-line-ant-tasks.xml:93: Unable to
find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\Java\jre7"
Total time: 0 seconds
對於日食
快速解決同樣的問題
將C:\\ Program Files \\ Java \\ jdk1.7.0_03 \\ lib \\ tools.jar復制到C:\\ Program Files \\ Java \\ jre7 \\ lib \\
此異常即將發生,因為JAVA_HOME被設置為C:\\ Program Files \\ Java \\ jre7並且Ant無法在其中找到tools.jar。
在Windows中,轉到計算機屬性,高級系統設置,高級環境變量
在我的案例“C:\\ Program Files \\ Java \\ jdk1.7.0_51”中添加一個名為“JAVA_HOME”的系統變量,將其文件夾設置到JDK位置
關閉命令提示符,重新打開它,它現在應該工作。
如果系統中同時安裝了JRE和JDK,請確保JDK在PATH變量中排在第一位。
我認為系統從左到右掃描PATH變量,不管先考慮什么。
在我的情況下(使用LinuxMint)我得到了同樣的錯誤。 當我在JRE之前在PATH變量中添加JDK時,它解決了我的問題。
我在Mac OS X中遇到了同樣的錯誤,但我能找到的所有答案都是針對Windows系統的,並且兩者的路徑都有所不同,這些解決方案對我來說都不起作用。 花了幾個小時后,我終於能夠通過以下方式修復它了:
將/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/lib/tools.jar復制到/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/ext
它也適用於Windows用戶:
將C:\\ Program Files \\ Java \\ jdk1.8.0_91 \\ lib \\ tools.jar復制到C:\\ Program Files \\ Java \\ jre8 \\ lib \\ ext
PS還要注意您在Eclipse中選擇的jdk和jre版本是兼容的。
選擇標准VM后單擊JRE Type窗口中的下一個按鈕,轉到名為JRE Definition的下一個窗口,您可以在其中找到Directory按鈕。
這對我有用。 即使添加了tools.jar,如果它顯示找不到javac。 單擊run-> external tools configuration - > jre - > seperate JRE確保指向jdk - > apply - > run然后運行build.xml文件Jusy確保在安裝的jre中指向jdk位置。 希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.