77

Possible Duplicate:
Unable to locate tools.jar

I'm trying to use ant to compile using this command :

 ant compile

I don't know if the problem comes from my windows 64bit, or by something else. Because I have java Installed in the 64 & 32 prog files.

Java 64 & 32

I downloaded apache-ant-1.8.2-bin and putted it in C:\Program Files\apache-ant-1.8.2

I tried to put ant everywhere, I switched also the ENV PATH between java 64 and 32 but everytime I get this error message :

Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar

I searched for tools.jar in the ant lib folder, in the java 64 and 32, but no trace of it in the system.

What do you think ?

Community
  • 1
  • 1
Wassim AZIRAR
  • 10,823
  • 38
  • 121
  • 174

5 Answers5

156

A JRE doesn't have a tools.jar, you need a JDK. Set your JAVA_HOME and PATH variables so that they point to a JDK, not a JRE.

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • 12
    Adding "C:\Program Files\Java\jdk1.7.0_65" to JAVA_HOME and "C:\Program Files\Java\jdk1.7.0_65\bin" to PATH did the trick. (jdk1.7.0_65 is for JDK 1.7 Update 65 and can vary) – Munchies Aug 04 '14 at 11:56
  • 6
    @Munchies actually, it's more elegant to add `%JAVA_HOME%/bin` to path. that way you need to change only one variable when you upgrade – Sean Patrick Floyd Aug 04 '14 at 12:15
  • 1
    on Windows try restarting your computer, worked for me after. – Christian Strang Nov 02 '14 at 14:08
  • Is Windows the only OS where restarting means you lose your currently open Windows? I just restart the cmd console until I see changes propagated there. Unless of course you've elected to be _elegant_ and some rogue script is overriding your JAVA_HOME path so that it's still pointing at the JRE – John Jan 19 '15 at 11:28
  • For me, adding JAVA_HOME in the windows classpath/path did not help - rather i had to create a new environment variable - JAVA_HOME within the eclipse and point it to JDK7 - that worked – JavaTec Feb 15 '16 at 17:52
20

I had similar issue and got solved by doing following ,

1) set JAVA_HOME as C:\Program Files (x86)\Java\jdk1.7.0\

2) ANT_HOME as F:\ant\apache-ant-1.8.4-bin\apache-ant-1.8.4

3) add both to 'path ' in system variables

Pramod
  • 3,217
  • 3
  • 20
  • 26
4

Please make sure that you are pointing to JDK and not a JRE. For example, you should set JAVA_HOME as "C:\Program Files\java\jdk1.6.0_26" and have %JAVA_HOME%\bin in your system path.

dotrc
  • 171
  • 2
  • 5
  • In my case the variable `CLASSPATH` pointing to `%JAVA_HOME%\jre\lib` was missing, see http://stackoverflow.com/a/26640589/2518971 – escalator Feb 02 '17 at 12:02
4

I had to copy C:\Program Files\Java\jdk1.6.0_26\lib\tools.jar to C:\Program Files\Java\jre6\lib\ext

Thanks anyway.

Wassim AZIRAR
  • 10,823
  • 38
  • 121
  • 174
3

tools.jar comes with JDK, but what happens in your case it looks for it within /Java/jre6. Change JAVA_HOME env var to one of your JDK home.

Art Licis
  • 3,619
  • 1
  • 29
  • 49