Android ant build : 无法找到 tools.jar。预计在 C:\Program Files\Java\jre7\lib\tools.jar 中找到它

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

ant build : unable to locate tools.jar. Expected find it in C:\Program Files\Java\jre7\lib\tools.jar

androidantui-automationbuild.xmlandroid-uiautomator

提问by Rikki Tikki Tavi

I know that this question is popular, but no one of solutions can help me. I used this, this, thisand thissolutions, but no one help me.

我知道这个问题很受欢迎,但没有任何解决方案可以帮助我。我使用了这个这个这个这个解决方案,但没有人帮助我。

I want to implement uiautomator Testsand need to build my build.xml with ant, but get this strange error.

我想实现uiautomator 测试并且需要用 ant 构建我的 build.xml,但是得到这个奇怪的错误。

I use Windows 8.1

我使用 Windows 8.1

My JAVA_HOME system variable set to c:\programs files\java\jdk1.7.0_51 and to c:\programs files(x86)\java\jdk1.7.0_51

我的 JAVA_HOME 系统变量设置为 c:\programs files\java\jdk1.7.0_51 和 c:\programs files(x86)\java\jdk1.7.0_51

My PATH system variable set also to %JAVA_HOME%/bin, my %ANT_HOME% is set to c:\apache-ant.

我的 PATH 系统变量也设置为 %JAVA_HOME%/bin,我的 %ANT_HOME% 设置为 c:\apache-ant。

But when I execute ant build in the android app derictory I get the

但是当我在 android 应用程序中执行 ant build 时,我得到了

unable to locate tools.jar. Expected find it in C:\Program Files\Java\jre7\lib\tools.jar
BUILD FAILED
Perhaps JAVA_HOME does not point to the JDK

But my JAVA_HOME points to right JDK ! I confused with this. I also rebuild my build several times, I've got the same.

但是我的 JAVA_HOME 指向正确的 JDK !我对此感到困惑。我也多次重建我的构建,我有同样的。

Will be glad if somebody help me.

如果有人帮助我会很高兴。

采纳答案by Rikki Tikki Tavi

I solved issue with setting %JAVA_HOME% to start of the PATH. It worked for me when I set it exactly to the start.

我解决了将 %JAVA_HOME% 设置为 PATH 开头的问题。当我将它完全设置为开始时,它对我有用。

回答by Smriti

I too had this problem and solved it by setting variables like this :

我也有这个问题并通过设置这样的变量来解决它:

[1] ANT_HOME - C:\apache-ant-1.9.3

[2] JAVA_HOME - C:\Program Files\Java\jdk1.7.0_21

[3] PATH - D:\Android_Development\android_sdk\platform-tools\;%ANT_HOME%\bin;%JAVA_HOME%\bin;D:\Android_Development\android_sdk\tools

Note : Set all these in System variables not in user variables.

注意:在系统变量中而不是在用户变量中设置所有这些。

This solved my problem.

这解决了我的问题。

Hope it helps.

希望能帮助到你。

回答by geek_sandeep

To Recover this problems you can just copy the tools.jar from "C:\ProgramFiles\Java\jdk1.7.0\lib" directly into "C:\Program Files\Java\jre7\lib\".You will successfully recover the problems.

要解决此问题,您只需将“C:\ProgramFiles\Java\jdk1.7.0\lib”中的tools.jar 直接复制到“C:\Program Files\Java\jre7\lib\”中即可。您将成功恢复问题.

It works!..

有用!..

回答by David Svarrer

In regards to the tools.jar, I experienced the following: when downloading ant, it came with open java 7. However, the system I had downloaded, uses Java 8 u 40 (the Oracleversion). Therefore, when I pointed the lib/jre via a softlink in linux, to the place of the tools.jar, I got the error, that now the version/subversion was not matching. This because ant was using version 7, and the tools.jar from Oraclewas now version 8.

关于tools.jar,我遇到了以下情况:下载ant的时候是open java 7的,但是我下载的系统是Java 8 u 40(Oracle版本)。因此,当我通过 linux 中的软链接将 lib/jre 指向tools.jar的位置时,出现错误,现在版本/subversion 不匹配。这是因为 ant 使用的是版本 7,而Oracle的 tools.jar现在是版本 8。

The solution was, to use the above help (with the setting of the JAVA_PATH to become my Oracleversion 8u40 of Java), such that both the compiler and the tools.jarfile is of same version.

解决方案是,使用上面的帮助(将 JAVA_PATH 设置为我的 Java 的Oracle版本 8u40),这样编译器和tools.jar文件都是相同的版本。

The scenario I am in, therefore has the jdk downloaded as it came from Oracle in my /home/david/Desktop/Android5.0/jdk1.8.0u40 directory - the Android packages as they came in /home/david/Desktop/Android5.0 directory, my Eclipse workspace in /home/david/workspace - and now I hope to be better to go.

我所处的场景,因此在我的 /home/david/Desktop/Android5.0/jdk1.8.0u40 目录中下载了来自 Oracle 的 jdk - Android 软件包,因为它们来自 /home/david/Desktop/Android5 .0 目录,我的 Eclipse 工作区在 /home/david/workspace - 现在我希望能更好地去。

The ant-file build.xml is placed in my /home/david/workspace directory - and it is looking like this:

ant 文件 build.xml 放在我的 /home/david/workspace 目录中 - 它看起来像这样:

<project>
    <target name="clean">
        <delete dir="build"/>
    </target>

    <target name="compile">
        <mkdir dir="build/classes"/>
        <javac srcdir="src" destdir="build/classes"/>
    </target>

    <target name="jar" depends="compile">
        <mkdir dir="build/jar"/>
        <jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
            <manifest>
                <attribute name="Main-Class" value="oata.HelloWorld"/>
            </manifest>
        </jar>
    </target>

    <target name="run" depends="jar">
        <java jar="build/jar/HelloWorld.jar" fork="true"/>
    </target>

</project>

The java file in this question - HelloWorld.java, is being put into the directory /home/david/workspace/build/src/oata - and it now compiles to its destination you can see above, and from there the jar file is being built too.

这个问题中的 java 文件 - HelloWorld.java,被放入目录 /home/david/workspace/build/src/oata - 现在它编译到你可以在上面看到的目的地,从那里开始 jar 文件也建了。

True - there are methods where one can make one version of Java pretend to be another - but I didn't want to go there, because I am setting up a build environment where I can do extracts from the repository, build, and storing of the built code into a download site.

是的 - 有些方法可以让一个版本的 Java 伪装成另一个版本 - 但我不想去那里,因为我正在设置一个构建环境,我可以在其中从存储库中提取、构建和存储构建的代码到一个下载站点。

The above build.xml sample is slightly modified from the following Ant tutorial for build: https://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html

上面的 build.xml 示例从以下用于构建的 Ant 教程中稍作修改:https: //ant.apache.org/manual/tutorial-HelloWorldWithAnt.html

Guys - hope it works for you too, because ant is really one of the best ways of building, as you can invoke it from the command line, you can make it pick files from the repository first (GitHub or BitBucket etc.), and then you can FTP the compiled result to your preferred download site for developers, you can zip together the code such that you have the version ready and zipped in worst case...

伙计们 - 希望它也适用于你,因为 ant 确实是最好的构建方式之一,因为你可以从命令行调用它,你可以让它首先从存储库(GitHub 或 BitBucket 等)中选择文件,并且然后您可以将编译结果通过 FTP 传输到您首选的开发人员下载站点,您可以将代码压缩在一起,以便在最坏的情况下准备好版本并压缩...

回答by konanki chiranjeevi

Copy the tools.jar from C:\Program Files\Java\jdk1.8.0_91\lib and pate to C:\Program Files\Java\jdk1.8.0_91\bin. It worked fine for me in my case

将 tools.jar 从 C:\Program Files\Java\jdk1.8.0_91\lib 复制到 C:\Program Files\Java\jdk1.8.0_91\bin。就我而言,它对我来说很好用

回答by ataraxis

  1. Set in the system-variables:

    • JAVA_HOME: C:\Program Files\Java\jdkVERSION
    • ANT_HOME: C:\Program Files\apache-ant-VERSION
    • PATH: %JAVA_HOME%\bin;%ANT_HOME%\bin;... (at the beginning of the PATH-variable)
  2. Remove everything related to Java/Ant from the user-variables

  3. Restart the commandline (!) to receive the new Variables in the context of the running instance.

  1. 系统变量中设置:

    • JAVA_HOME: C:\Program Files\Java\jdkVERSION
    • ANT_HOME: C:\Program Files\apache-ant-VERSION
    • PATH: %JAVA_HOME%\bin;%ANT_HOME%\bin;...(在 PATH 变量的开头)
  2. 用户变量中删除与 Java/Ant 相关的所有内容

  3. 重新启动命令行 (!) 以在正在运行的实例的上下文中接收新变量。

回答by selvan127

kindly set the system variable for JDK not JRE. this will solve the problem

请为 JDK 而不是 JRE 设置系统变量。这将解决问题

回答by Vikas Yadav

Follow the below steps to resolve the issue:

请按照以下步骤解决问题:

Goto Control Panel -> Set below environment variables:

转到控制面板-> 设置以下环境变量:

  1. ANT_HOME - C:\apache-ant-1.9.14

  2. JAVA_HOME - C:\Program Files\Java\jdk1.8.0_181

  3. PATH - %ANT_HOME%\bin;%JAVA_HOME%\bin;

  1. ANT_HOME - C:\apache-ant-1.9.14

  2. JAVA_HOME - C:\Program Files\Java\jdk1.8.0_181

  3. 路径 - %ANT_HOME%\bin;%JAVA_HOME%\bin;

回答by Sudha

This is because editing the environmental variables instead of creating new one. Though java home and path variables were set, it is not pointed properly. Just delete java home and path variable and add it again. This one fixed my issue.

这是因为编辑环境变量而不是创建新环境变量。虽然设置了 java home 和 path 变量,但没有正确指向。只需删除 java home 和 path 变量并重新添加即可。这个解决了我的问题。

回答by Ganesh Koli

Check the value of JAVA_HOMEand PATHvariable, sometime you might be putting

检查JAVA_HOMEPATH变量的值,有时你可能会

JAVA_HOME="C:\Program Files\Java\jdk1.8.0\bin" .

instead of

代替

JAVA_HOME="C:\Program Files\Java\jdk1.8.0" .

and PATH=%JAVA_HOME%\bin;%PATH% .

PATH=%JAVA_HOME%\bin;%PATH% .

just echo out the PATH variable in CLI.

只需在 CLI 中回显 PATH 变量即可。

echo %PATH%.