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

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
Derek
  • 4,985
  • 4
  • 20
  • 9
  • 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. – Sripathi Krishnan Apr 11 '10 at 19:17
  • 1
    It was told him in his previous topic: http://stackoverflow.com/questions/2612202/where-do-you-download-a-package-with-java-exe – BalusC Apr 11 '10 at 19:48
  • 1
    @BalusC - I provided explicit link to the JDK (which is a "widget" as it seems :) ) - that should spare more mistakes. – Bozho Apr 11 '10 at 19:52
  • 1
    @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. – BalusC Apr 11 '10 at 19:53

8 Answers8

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.

jayshao
  • 2,167
  • 2
  • 15
  • 17
26

You need JDK for that.

Set JAVA_HOME to point to the JDK.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • 2
    Setting `JAVA_HOME` is not necessary at all. – Michael Piefel Oct 25 '11 at 08:03
  • 2
    @MPi It was for me. Perhaps because I already had a JRE installed beforehand. – alnorth29 Oct 05 '12 at 09:56
  • 1
    You would think this would work, but I still had to put the JDK location in the path. – awesomo Nov 29 '12 at 19:22
  • 2
    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 – Sun Feb 18 '13 at 22:22
  • 2
    Michael, it sure was necessary. The misleading blanket statements are really what are not necessary. – Drew Apr 22 '14 at 13:14
  • @MichaelPiefel How is it not necessary? It fixed the problem for me (and others). Perhaps there is an even easier and/or better solution? –  Aug 05 '14 at 15:57
  • 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? – Michael Piefel Aug 06 '14 at 08:35
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.

Community
  • 1
  • 1
Drew
  • 4,215
  • 3
  • 26
  • 40
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.

Scott
  • 51
  • 1
  • 1
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.

Prachi
  • 3,584
  • 2
  • 24
  • 39
  • 1
    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 – barca_d Nov 07 '14 at 09:12
  • Yes, I observed this! although this is a sort of patch, but it will work for now. – Prachi Nov 13 '14 at 05:39
1

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

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.

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.

demongolem
  • 9,474
  • 36
  • 90
  • 105
babu
  • 1