Ant error when trying to build file, can't find tools.jar?
Solution 1
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.
Solution 2
You need JDK for that.
Set JAVA_HOME
to point to the JDK.
Solution 3
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:
Adding a ANT_HOME environment variable that points to the ROOT directory of your Apache ant directory location. (Not the bin sub-dir!)
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!)
Appended %ANT_HOME%\bin;%JAVA_HOME%\bin to the PATH environment variable.
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.
Solution 4
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.
Solution 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.
Derek
Software Developer, Web Designer, Laid Back Relax cool type of brother.
Updated on July 09, 2022Comments
-
Derek almost 2 years
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...
-
matbrgz about 14 yearsIt is back to JDK from J2SDK.
-
jayshao about 14 yearsYeah, looks like Oracle's straightened up the branding - actually I think the new DL page is probably clearer than the old Sun one
-
Michael Piefel over 12 yearsSetting
JAVA_HOME
is not necessary at all. -
User about 12 years(if javac is not found add Java's bin directory to PATH)
-
alnorth29 over 11 years@MPi It was for me. Perhaps because I already had a JRE installed beforehand.
-
awesomo over 11 yearsYou would think this would work, but I still had to put the JDK location in the path.
-
Sun about 11 yearsFor 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_37
-
Drew about 10 yearsMichael, it sure was necessary. The misleading blanket statements are really what are not necessary.
-
Admin almost 10 years@MichaelPiefel How is it not necessary? It fixed the problem for me (and others). Perhaps there is an even easier and/or better solution?
-
Michael Piefel almost 10 yearsI may have been overly brief, but my statement remains true. You need the JDK, but not
JAVA_HOME
. When you use thejava
binary from the JDK’sbin
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? -
barca_d over 9 yearsThis 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 disappeared
-
Prachi over 9 yearsYes, I observed this! although this is a sort of patch, but it will work for now.