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

103,134

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:

  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.

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.

Share:
103,134
Derek
Author by

Derek

Software Developer, Web Designer, Laid Back Relax cool type of brother.

Updated on July 09, 2022

Comments

  • Derek
    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
    matbrgz about 14 years
    It is back to JDK from J2SDK.
  • jayshao
    jayshao about 14 years
    Yeah, 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
    Michael Piefel over 12 years
    Setting JAVA_HOME is not necessary at all.
  • User
    User about 12 years
    (if javac is not found add Java's bin directory to PATH)
  • alnorth29
    alnorth29 over 11 years
    @MPi It was for me. Perhaps because I already had a JRE installed beforehand.
  • awesomo
    awesomo over 11 years
    You would think this would work, but I still had to put the JDK location in the path.
  • Sun
    Sun about 11 years
    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_37
  • Drew
    Drew about 10 years
    Michael, it sure was necessary. The misleading blanket statements are really what are not necessary.
  • Admin
    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
    Michael Piefel almost 10 years
    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?
  • barca_d
    barca_d over 9 years
    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 disappeared
  • Prachi
    Prachi over 9 years
    Yes, I observed this! although this is a sort of patch, but it will work for now.