Java Ant + Vista 64:“无法定位 tools.jar”(jre/jdk 冲突?)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4378535/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 16:43:27  来源:igfitidea点击:

Ant + Vista 64 : "Unable to locate tools.jar" (jre/jdk conflict?)

antwindows-vistajava

提问by idiotprogrammer

I'm trying to use ant in a vista 64 environment to build some docbook/xml files.

我正在尝试在 vista 64 环境中使用 ant 来构建一些 docbook/xml 文件。

However, I can't resolve this error message. Anybody have suggestions?

但是,我无法解决此错误消息。有人有建议吗?

C:\Users\Robert Admin>ant Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\li b\tools.jar Buildfile: build.xml does not exist! Build failed

C:\Users\Robert Admin>ant 无法找到 tools.jar。预计在 C:\Program Files\Java\jre6\li b\tools.jar 中找到它 Buildfile: build.xml 不存在!构建失败

Googling around, I see that this tools.jar message is the result of ant not being able to find the jdk. In fact, C:\Program Files\Java\jre6\li b\tools.jar is a JRE installed with another program (I'm guessing). Tools.jar is located here: C:\Program Files\Java\jdk1.6.0_22\lib

谷歌搜索,我看到这个tools.jar消息是ant找不到jdk的结果。事实上,C:\Program Files\Java\jre6\li b\tools.jar 是一个安装了另一个程序的 JRE(我猜)。Tools.jar 位于:C:\Program Files\Java\jdk1.6.0_22\lib

I can't seem to tell Ant to look in the JDK path, only the JRE path which was already there. (Judging from the Ant documentation, it seems that JRE is insufficient).

我似乎无法告诉 Ant 查看 JDK 路径,只能查看已经存在的 JRE 路径。(从 Ant 文档来看,似乎 JRE 是不够的)。

C:\Users\Robert Admin>echo %JAVA_HOME%

C:\Program Files\Java\jdk1.6.0_22\bin

C:\Users\Robert Admin>ant

Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\li
b\tools.jar
Buildfile: build.xml does not exist!
Build failed

C:\Users\Robert Admin>echo %ANT_HOME%

I:\My Documentslatest\ant    
C:\Users\Robert Admin>where java

C:\Windows\System32\java.exe
C:\Program Files (x86)\Java\jre6\bin\java.exe
C:\Program Files\Java\jdk1.6.0_22\bin\java.exe

C:\Users\Robert Admin>java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)

Update #1. I tried uninstalling the 64 bit jdk and installing the 32 bit jdk. Result:

更新#1。我尝试卸载 64 位 jdk 并安装 32 位 jdk。结果:

C:\Users\Robert Admin>java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)

C:\Users\Robert Admin>ant
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\li
b\tools.jar
Buildfile: build.xml does not exist!
Build failed
C:\Users\Robert Admin>echo %JAVA_HOME%
C:\Program Files (x86)\Java\jdk1.6.0_22\bin

采纳答案by Dan Azlin

I had this problem on a 64-bit Windows 7 machine and Ant 1.8.2. The solution was to use the admin tools mentioned by #bigfix to set the environment variables. Follow the Ant installation instructions for Windows. But do not set the path as %ANT_HOME%\bin. Instead, use an explicit path such as C:\jdk-1.5.0.05\bin.

我在 64 位 Windows 7 机器和 Ant 1.8.2 上遇到了这个问题。解决方案是使用#bigfix 提到的管理工具来设置环境变量。按照适用于 Windows 的 Ant 安装说明进行操作。但不要将路径设置为 %ANT_HOME%\bin。而是使用显式路径,例如 C:\jdk-1.5.0.05\bin。

My first test failed because my command window was already open and using the old env vars. Close it and open a new one. Then try the test. It worked for me.

我的第一个测试失败了,因为我的命令窗口已经打开并使用旧的 env vars。关闭它并打开一个新的。然后尝试测试。它对我有用。

回答by phillip

why don't you try the 32 bit version. there could be a problem between the two versions you have installed being 32 and 64. try the 32 bit version so ur not seeing any 64 bit versions.

你为什么不试试 32 位版本。您安装的两个版本 32 和 64 之间可能存在问题。尝试 32 位版本,这样您就看不到任何 64 位版本。

it should fix ur problem.

它应该解决你的问题。

回答by bigfix

I fixed this by creating JAVA_HOME in computer-> properties-> env variables Manual setup in command line did not work -b

我通过在计算机-> 属性-> 环境变量中创建 JAVA_HOME 解决了这个问题 在命令行中手动设置不起作用 -b

回答by Gary Brunton

I had the same problem because my JAVA_HOME path was set incorrectly (just like the OP's). It was set to the bin of the jdk.

我遇到了同样的问题,因为我的 JAVA_HOME 路径设置不正确(就像 OP 一样)。它被设置为jdk的bin。

So it was set to: C:\Program Files (x86)\Java\jdk1.6.0_25\bin

所以设置为:C:\Program Files (x86)\Java\jdk1.6.0_25\bin

When it should have been set to: C:\Program Files (x86)\Java\jdk1.6.0_25

当它应该设置为:C:\Program Files (x86)\Java\jdk1.6.0_25

Updating this environmental variable fixed it for me.

更新这个环境变量为我修复了它。

回答by Inco Mob

I know this thread is some what old..but i faced it just now too..what i did was copy that tools.jar into jre/lib folder and worked fine.

我知道这个线程有些旧..但我现在也遇到了它..我所做的是将该工具.jar复制到jre/lib文件夹中并且工作正常。

I'm in Windows 7 , JDK 1.7 environment and trying to install ant 1.8.2

我在 Windows 7 ,JDK 1.7 环境中并尝试安装 ant 1.8.2

Thanks

谢谢

回答by Suman

I solved the problem by creating system variable JAVA_HOME to C:\Program Files\Java\jdk1.6.0_25. Don't put the semi colon after it. First of all I put the semi colon and there was an error. I removed the semi colon and it worked.

我通过将系统变量 JAVA_HOME 创建到 C:\Program Files\Java\jdk1.6.0_25 解决了这个问题。后面不要加分号。首先,我放了分号,然后出现了错误。我去掉了分号,它起作用了。

回答by radix_zero

you may be using the java in the C:\Windows\system32 directory rather then the installed JDK. I set a JAVA_HOME environmental variable and put %JAVA_HOME%\bin at the start of my path and the problems when away.

您可能正在使用 C:\Windows\system32 目录中的 java 而不是已安装的 JDK。我设置了一个 JAVA_HOME 环境变量,并将 %JAVA_HOME%\bin 放在我的路径的开头和离开时的问题。

回答by Shibaram Sahoo

I had this issue with Environment as :

我对环境有这个问题:

  • Windows 7
  • Java version jdk1.6.0_33
  • apache-ant-1.6.5
  • Windows 7的
  • Java版jdk1.6.0_33
  • apache-ant-1.6.5

I Was getting ant build message as "Unable to locate tools.jar. Expected to find it in E:\Java\jre6\lib\tools.jar", where my JDK was installed at E:\Java\jdk1.6.0_33\and JRE at E:\Java\jre6\

我收到 ant build 消息为“ Unable to locate tools.jar. Expected to find it in E:\Java\jre6\lib\tools.jar”,我的 JDK 安装E:\Java\jdk1.6.0_33\E:\Java\jre6\

Cause:

原因:

My issue was that I have ANT_HOMEwas set twice in the PATH system Environment variable at two different places (means some other variables in between).

我的问题是我ANT_HOME在两个不同位置的 PATH 系统环境变量中设置了两次(意味着中间的一些其他变量)。

Solution:

解决方案:

I removed the ANT_HOMEvariable that pointed to the wrong location and everything worked fine with me.

我删除了ANT_HOME指向错误位置的变量,一切正常。

回答by Vlado

All you need is to set JAVA_HOME path in your environment. In Windows 7 go to "System Properties -> Advanced -> Environment Variables" and add JAVA_HOME. The value in my case was:

您只需要在您的环境中设置 JAVA_HOME 路径。在 Windows 7 中,转到“系统属性 -> 高级 -> 环境变量”并添加 JAVA_HOME。在我的案例中的价值是:

C:\Program Files\Java\jdk1.7.0_07

C:\Program Files\Java\jdk1.7.0_07

This resolved the issue for me. This variable points Ant to the correct Java location.

这为我解决了这个问题。此变量将 Ant 指向正确的 Java 位置。

回答by gangjiang

I once faced the same problem of ant setup. The promotion is just the same as

我曾经遇到过同样的问题ant setup。促销是一样的

Unable to locate tools.jar`. Expected to find it in C:\Program Files\Java\jre6\li b\tools.jar 
Buildfile: build.xml does not exist! Build failed. 

I deleted all jre path in %PATH%environment and add jdk bin path. Finally I type %ANT_PATH%/bininstead of %ANT_PATH%\bin. It works.

我删除了%PATH%环境中的所有 jre 路径并添加了 jdk bin 路径。最后我输入%ANT_PATH%/bin而不是%ANT_PATH%\bin. 有用。

May help.

可能会有所帮助。