简体   繁体   English

Ant“JAVA_HOME 不指向 JDK” - 但它确实如此

[英]Ant “JAVA_HOME does not point to the JDK” - but it does

I cannot run my Ant build.xml since I updated to java 1.7.0_52 (or there about).自从我更新到 java 1.7.0_52(或大约)以来,我无法运行我的 Ant build.xml。 I have been running it for years through Eclipse locally on my Windows 7 laptop - but with this latest jave jdk update somethings different (?).我多年来一直在我的 Windows 7 笔记本电脑上通过 Eclipse 本地运行它 - 但是这个最新的 jave jdk 更新有些不同(?)。

BUILD FAILED
C:\workspace\WaterAspectsModel3\build.xml:329: 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 "D:\Morten\Java\jdk1.7.0_52"

This is my jdk!这是我的jdk! So JAVA_HOME is pointing to a jdk (as is also clear from the error message).所以 JAVA_HOME 指向一个 jdk(从错误消息中也很清楚)。 I have my JAVA_HOME with bin folder in my path as always.我的 JAVA_HOME 和 bin 文件夹一如既往地在我的路径中。 I've configured Eclipse - external tools configuration - with a JRE pointing to the same D:\\Morten\\Java\\jdk1.7.0_52 (through "Separate JRE" setting).我已经配置了 Eclipse - 外部工具配置 - 一个 JRE 指向相同的 D:\\Morten\\Java\\jdk1.7.0_52 (通过“单独的 JRE”设置)。 And I've tried a number of other configurations - all without luck.我已经尝试了许多其他配置 - 都没有运气。

I've been reading the tonnes of answers on lists here and other places and think I've tried all suggestions.我一直在阅读这里和其他地方列表中的大量答案,并认为我已经尝试了所有建议。 Most seem to be cases where JAVA_HOME actually points to a jre and just needs to be corrected to jdk or there's a ";"大多数情况似乎是 JAVA_HOME 实际上指向 jre 并且只需要更正为 jdk 或者有一个“;” in the path or something like that.在路径或类似的东西。 None of these seem to apply in my case.这些似乎都不适用于我的情况。

Any suggestions?有什么建议么?

I was having the same message when running ANT through Eclipse.通过 Eclipse 运行 ANT 时,我遇到了相同的消息。

What worked for me:什么对我有用:

  1. In Eclipse, access the menu: "Window -> Preferences";在 Eclipse 中,访问菜单:“Window -> Preferences”;
  2. Access "Ant -> Runtime", at the tree;在树中访问“Ant -> Runtime”;
  3. Access the Classpath tab;访问类路径选项卡;
  4. Expand the "Global Entries" item;展开“全局条目”项;
  5. Inside Global Entries, the path to tools.jar was wrong.在全局条目中, tools.jar的路径是错误的。 It was pointing to an older version of Java;它指向旧版本的 Java;
  6. I removed the wrong entry and added the correct one with "Add External Jars" button.我删除了错误的条目并使用“添加外部罐子”按钮添加了正确的条目。 It worked.有效。

在此处输入图片说明

解决方案“ Had to copy C:\\Program Files\\Java\\jdk1.6.0_10\\lib\\tools.jar to C:\\Program Files\\Java\\jre6\\lib\\ext ”从这里开始非常有帮助并且对我有用。

The real message is that Ant can't find com.sun.tools.javac.Main .真正的信息是 Ant 找不到com.sun.tools.javac.Main

Which, together with the fact that the latest "Sun" (Oracle) JDK is 1.7.0_13 (or maybe _14, but definitely not the "_52" that your install dir indicates), makes me think that you're not using a distribution that Ant recognizes.其中,加上最新的“Sun”(Oracle)JDK 是 1.7.0_13(或者可能是 _14,但绝对不是您的安装目录指示的“_52”)这一事实,让我认为您没有使用发行版蚂蚁认得。 You can verify this by running jar tvf $JAVA_HOME/lib/tools.jar , and looking for that class.您可以通过运行jar tvf $JAVA_HOME/lib/tools.jar并查找该类来验证这一点。

The Ant Manual talks about ways to work with different compilers. Ant 手册讨论了使用不同编译器的方法。 Since I've only used "Sun" compilers, I'm afraid that I can't give you any pointers.因为我只用过“Sun”编译器,恐怕我不能给你任何指点。


Edit: you could also try setting fork="yes" in your build file.编辑:您也可以尝试在构建文件中设置fork="yes" This should run the compiler executable rather than trying to invoke the compiler class.这应该运行编译器可执行文件,而不是尝试调用编译器类。

尝试将JAVA_HOME\\bin添加到您的环境env PATH

将 JAVA_HOME 添加到 Eclipse-Preferences-Java-Build Path-Classpath 变量。

Sorry for the unearthing,对不起,发掘

I had the same problem, my solution doesn't need any modification in environment variables, and works for a recent JDK where the tools.jar can't be found.我遇到了同样的问题,我的解决方案不需要对环境变量进行任何修改,并且适用于无法找到 tools.jar 的最新 JDK。

Just go in the small down-arrow next to the ant run button Then click "Configure external tools" Then in JRE tab Select a JDK installed on your computer, not a JRE, no problems if the selected JDK is not the same JDK/JRE as in your project.只需进入ant run按钮旁边的小向下箭头然后单击“配置外部工具”然后在JRE选项卡中选择计算机上安装的JDK,而不是JRE,如果选择的JDK不是相同的JDK / JRE,则没有问题就像在你的项目中一样。

It should be work now.现在应该可以工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM