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

8

42

When I run ant it says:

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

I just downloaded this one:

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

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

Cordage answered 11/4, 2010 at 18:58 Comment(4)
You need to download JDK (instead of JRE) from sun's website. JDK contains binaries to compile your code. The JRE just contains binaries to execute already compiled code.Eudosia
It was told him in his previous topic: #2612702Tref
@Tref - I provided explicit link to the JDK (which is a "widget" as it seems :) ) - that should spare more mistakes.Quadrivalent
@Bozho: Yes, I upvoted you because of the direct link :) My answer in his previous topic however do contain download buttons to both JRE and JDK.Tref
S
45

Java ships in 2 versions: JRE & SDK (used to be called 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)

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.

Salonika answered 11/4, 2010 at 19:18 Comment(3)
It is back to JDK from J2SDK.Curcio
Yeah, looks like Oracle's straightened up the branding - actually I think the new DL page is probably clearer than the old Sun oneSalonika
(if javac is not found add Java's bin directory to PATH)Pint
Q
26

You need JDK for that.

Set JAVA_HOME to point to the JDK.

Quadrivalent answered 11/4, 2010 at 19:9 Comment(7)
Setting JAVA_HOME is not necessary at all.Antonina
@MPi It was for me. Perhaps because I already had a JRE installed beforehand.Seale
You would think this would work, but I still had to put the JDK location in the path.Cairistiona
For me, I had to change the JAVA_HOME because it was part of the batch file. I put a REM in front of the original entry, then put the revised JAVA_HOME entry in the line below. REM set JAVA_HOME=.\..\tools\java\jre set JAVA_HOME=C:\Progra~1\Java\jdk1.6.0_37Musketeer
Michael, it sure was necessary. The misleading blanket statements are really what are not necessary.Remand
@MichaelPiefel How is it not necessary? It fixed the problem for me (and others). Perhaps there is an even easier and/or better solution?Jari
I may have been overly brief, but my statement remains true. You need the JDK, but not JAVA_HOME. When you use the java binary from the JDK’s bin path to start ANT, it will work as well. How do you suppose the OP’s ANT created the path that was in the error message?Antonina
R
19

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:

  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.

Remand answered 22/4, 2014 at 13:35 Comment(0)
P
5

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.

Pachston answered 8/5, 2012 at 16:8 Comment(0)
O
5

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.

Ouphe answered 7/8, 2014 at 12:11 Comment(2)
This is a really useful answer. The error seemed to occur out of the blue for me, I checked the classpath and it was pointing to JDK just as it is normal. The problem must have been related to an update that Java prompted me to install a day earlier, which apparently modified JRE such that tools.jar was removed from the lib path. What I did to was copy the tools.jar from JDK/lib to JRE/lib and the error disappearedWobbling
Yes, I observed this! although this is a sort of patch, but it will work for now.Ouphe
C
1

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

Cadge answered 27/10, 2014 at 10:10 Comment(0)
R
0

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.

Rictus answered 26/12, 2013 at 6:43 Comment(0)
V
0

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.

Verruca answered 29/5, 2014 at 14:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.