Java 尝试构建文件时出现 Ant 错误,找不到 tools.jar?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2618281/
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-13 09:57:30  来源:igfitidea点击:

Ant error when trying to build file, can't find tools.jar?

javadeploymentanttools.jar

提问by Derek

When I run ant it says:

当我运行 ant 时,它说:

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

What package can I use to download the file required > C:\Program Files\Java\jre6\lib\tools.jar

我可以使用什么包来下载所需的文件 > C:\Program Files\Java\jre6\lib\tools.jar

I just downloaded this one:

我刚下载了这个:

jre-6u19-windows-i586-s.exe

jre-6u19-windows-i586-s.exe

but unfortunately it appears that it was not on it...

但不幸的是,它似乎不在上面......

回答by Bozho

You need JDKfor that.

为此,您需要JDK

Set JAVA_HOMEto point to the JDK.

设置JAVA_HOME为指向 JDK。

回答by jayshao

Java ships in 2 versions: JRE & SDK (used to be called JDK)

Java 有 2 个版本:JRE 和 SDK(以前称为 JDK)

The JRE in addition to not containing the compiler, also doesn't contain all of the libraries available in the JDK (tools.jar is one of them)

JRE 除了不包含编译器,也不包含 JDK 中可用的所有库(tools.jar 就是其中之一)

When you download Java at: http://java.sun.com/javase/downloads/index.jsp, make sure to select the JDK version and install it. If you have both a JDK & JRE, make sure that ANT is using the JDK, you can check JAVA_HOME (environment variable), and on the commandline if you do "javac -version" you should get a version description.

当您从http://java.sun.com/javase/downloads/index.jsp下载 Java 时,请确保选择 JDK 版本并安装它。如果您同时拥有 JDK 和 JRE,请确保 ANT 正在使用 JDK,您可以检查 JAVA_HOME(环境变量),如果您执行“javac -version”,您应该在命令行中获得版本描述。

回答by Scott

I was having the same problem, none of the posted solutions helped. Finally, I figured out what I was doing wrong. When I installed the Java JDK it asked me for a directiy where I wanted to install. I changed the directory to where I wanted the code to go. It then asked for a directory where it could install the Runtime Environment and I selected the SAME DIRECTORY where I installed the JDK. It over wrote my lib folder and erased the tools.jar. Be sure to use different folders during the install. I used my custom folder for the JDK and the default folder for the RE and everything worked fine.

我遇到了同样的问题,发布的解决方案都没有帮助。最后,我发现我做错了什么。当我安装 Java JDK 时,它询问我要安装的目录。我将目录更改为我想要代码的位置。然后它询问一个可以安装运行时环境的目录,我选择了安装 JDK 的 SAME DIRECTORY。它覆盖了我的 lib 文件夹并删除了 tools.jar。确保在安装过程中使用不同的文件夹。我为 JDK 使用了我的自定义文件夹,为 RE 使用了默认文件夹,一切正常。

回答by Sudheep Vallipoyil

Just set your java_home property with java home (eg:C:\Program Files\Java\jdk1.7.0_25) directory. Close command prompt and reopen it. Then error relating to tools.jar will be solved. For the second one("build.xml not found ") you should have to ensure your command line also at the directory where your build.xml file resides.

只需使用 java home (eg:C:\Program Files\Java\jdk1.7.0_25) 目录设置您的 java_home 属性。关闭命令提示符并重新打开它。然后与tools.jar 相关的错误将被解决。对于第二个(“build.xml not found”),您还应该确保您的命令行也位于您的 build.xml 文件所在的目录中。

回答by Drew

Using suggestions from answers on this page and this other one (ANT_HOME is set incorrectly or ant could not be located), the ultimate fix was the following:

使用此页面和另一个页面上的答案的建议(ANT_HOME 设置不正确或无法定位 ant),最终修复如下:

  1. Adding a ANT_HOME environment variable that points to the ROOT directory of your Apache ant directory location. (Not the bin sub-dir!)

  2. Adding a JAVA_HOME environment variable that points to the ROOT directory of your Java JDK (or SDK) directory location. (NOT your JRE and not the bin sub-dir!)

  3. Appended %ANT_HOME%\bin;%JAVA_HOME%\bin to the PATH environment variable.

  4. Make sure you close any command window(s) that were open prior to the changes above. Only command windows opened after the changes will have the updated environment variables.

  1. 添加指向 Apache ant 目录位置的 ROOT 目录的 ANT_HOME 环境变量。(不是 bin 子目录!)

  2. 添加指向 Java JDK(或 SDK)目录位置的 ROOT 目录的 JAVA_HOME 环境变量。(不是您的 JRE,也不是 bin 子目录!)

  3. 将 %ANT_HOME%\bin;%JAVA_HOME%\bin 附加到 PATH 环境变量。

  4. 确保关闭在上述更改之前打开的所有命令窗口。只有在更改后打开的命令窗口才会具有更新的环境变量。

回答by babu

Sometimes while installing JDK, you may get a dll is missing error. Because of this, it won't copy the tools.jar file to the java folder. So please reinstall the JDK in a different location and if it is successful then you will see the tools.jar file.

有时在安装 JDK 时,您可能会收到 dll is missing 错误。因此,它不会将 tools.jar 文件复制到 java 文件夹。因此,请在其他位置重新安装 JDK,如果成功,您将看到 tools.jar 文件。

回答by Prachi

I found that even though my path is set to JDK, the ant wants the tools.jar from jre folder. So just copy paste the tools.jar folder from JDK to jre.

我发现即使我的路径设置为 JDK,蚂蚁也需要 jre 文件夹中的 tools.jar。因此,只需将 tools.jar 文件夹从 JDK 复制粘贴到 jre。

回答by Naresh Lakoji

I was also getting the same problem, but i uninstalled all updates of java and now it is working very fine....

我也遇到了同样的问题,但是我卸载了所有 Java 更新,现在它工作得很好....