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

10

27

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

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

I use 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

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

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

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.

Will be glad if somebody help me.

Spruill answered 24/2, 2014 at 14:7 Comment(2)
Did you set these variables in PATH variable as well in system environment variables?Twi
also add %JAVA_HOME%\bin to PATH system variablePleurisy
S
11

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

Spruill answered 24/2, 2014 at 15:33 Comment(0)
T
40

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.

Twi answered 24/2, 2014 at 16:47 Comment(5)
I was setting ANT_HOME and JAVA_HOME in user variables. After your answer everything is working perfectly fine. 1 upvote for telling correct variablePaphian
I had defined JAVA_HOME , ANT_HOME as in the other Q&A but this one only worked.Honorary
Awesome. Mine was JAVA_HOME - C:\Program Files\Java\jdk1.8.0_73\bin so I removed the bin and it works fine now.Bounce
Had the same problem but it got resolved with the help of your answer. It did work for user variables thoughWedurn
I had the exact problem. I was sure that I had JAVA_HOME set correctly, however it was set under user variables, when I put the same property under system variable it worked perfectlyHumanoid
M
18

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.

It works!..

Mikvah answered 13/6, 2014 at 18:53 Comment(1)
It solved for me - but I've used the "Create shortcut" option. I'm from Linux world, so I like to link files :)Upholster
S
11

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

Spruill answered 24/2, 2014 at 15:33 Comment(0)
O
2

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 Oracle version). 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 Oracle was now version 8.

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

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.

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

<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.

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.

The above build.xml sample is slightly modified from the following Ant tutorial for build: 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...

Od answered 3/4, 2015 at 7:19 Comment(0)
S
2

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

Sarmentose answered 12/7, 2016 at 1:54 Comment(0)
L
2
  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.

Luz answered 14/3, 2017 at 19:15 Comment(0)
R
0

Check the value of JAVA_HOME and PATH variable, sometime you might be putting

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% .

just echo out the PATH variable in CLI.

echo %PATH%.
Rasla answered 27/12, 2015 at 18:38 Comment(0)
T
0

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

Tennilletennis answered 12/12, 2019 at 12:43 Comment(0)
H
0

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;

Hyperploid answered 3/4, 2020 at 8:20 Comment(0)
L
0

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.

Lipp answered 15/4, 2020 at 8:18 Comment(1)
Dear Sudha thank you very much for contributing. as you see the question is very old!. your answer a great and setting path again is good enough to solve it. Please try to contribute more to new questions with updated solutions in this way you'll help the community more.Mohamed

© 2022 - 2024 — McMap. All rights reserved.