"Unable to locate tools.jar" when running ant [duplicate]
Asked Answered
S

5

49

When running ant, I get the following message:

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

I have JAVA_HOME set to C:\Program Files\Java\jdk1.7.0_02, PATH includes C:\Program Files (x86)\Java\jdk1.7.0_02\bin, CLASSPATH includes C:\Program Files (x86)\Java\jdk1.7.0_02, and ANT_HOME is set to C:\ant.

It seems that ant is ignoring all of these settings and looking for the tools.jar somewhere else. There are no environment variables which point to the jre6 path. Any ideas why?

Snobbery answered 2/2, 2012 at 20:27 Comment(5)
are you sure there are no classpath settings in ant folder?Brutalize
Not that I can tell, but I might be missing something. What would I be looking for to find that?Snobbery
PLease verify the JAVA_HOME path of your system environment variable... It must be like "C:\Program Files\Java\jdk1.6.0_12\" and try to kill all java process and try after it will run 100%.Benempt
Install JDK, Add new system variable "JAVA_HOME" to <path to Java sdk folder> and add JAVA_HOME%\bin to system variable "path"Exuviate
maybe you have updated the JREs in the OS, and the addition has added in the "path" of the environment variables an entry "... / Oracle / jer" that overwrites your JAVA_HOME. try to remove it from the "path" by leaving JAVA_HOME.Soke
A
36

There are two directories that looks like JDK.

  C:\Program Files\Java\jdk1.7.0_02
  C:\Program Files (x86)\Java\jdk1.7.0_02\

This may be due to both 64 bit and 32 bit JDK installed? What ever may be the case, the java.exe seen by ant.bat should from the JDK. If the JRE's java.exe comes first in the path, that will be used to guess the JDK location.

Put 'C:\Program Files (x86)\Java\jdk1.7.0_02\bin' or 'C:\Program Files\Java\jdk1.7.0_02' as the first argument in the path.

Further steps:

You can take output of ant -diagnostics and look for interesting keys. (assuming Sun/Oracle JDK).

 java.class.path 
 java.library.path
 sun.boot.library.path

(in my case tools.jar appears in java.class.path)

Avan answered 4/2, 2012 at 14:56 Comment(9)
Thanks for the -diagnostics tip. This shows that the java.home system property is pointing to the 1.6 JRE, despite all the environment variables pointing to 1.7. Doesn't fix the problem, but it's a starting point for further investigation.Snobbery
ant expects 'JDK'. The java.exe from a JDK must be appear first. See comment from Mads HansenAvan
I have this same error.when I have tried ant -diagnostics I got java.home : C:\Program Files\Java\jre6.But I have set JAVA_HOME to C:\Program Files (x86)\Java\jdk1.6.0_25.What is the issueDesmund
@ user1767260 : is that C:\Program Files (x86)\Java\jdk1.6.0_25 first entry in the path?Avan
No..but there is no entry for jre.Desmund
@ user1767260 : open command window and try 'where java'.Avan
C:\Windows\System32\java.exe C:\Program Files (x86)\Java\jdk1.6.0_25\bin\java.exeDesmund
Any idea?I am stuck in this iisue :(Desmund
The java.exe in system32 is a dummy: See mindprod.com/jgloss/javaexe.html#MULTIPLES. You can put your JDK/bin as the first entry.Avan
V
11

I was also having the same problem So I just removed the JDK path from the end and put it in start even before all System or Windows 32 paths.

Before it was like this:

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Users\Rajkaran\AppData\Local\Smartbar\Application\;C:\Users\Rajkaran\AppData\Local\Smartbar\Application\;C:\Program Files\doxygen\bin;%JAVA_HOME%\bin;%ANT_HOME%\bin

So I made it like this:

%JAVA_HOME%\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Users\Rajkaran\AppData\Local\Smartbar\Application\;C:\Users\Rajkaran\AppData\Local\Smartbar\Application\;C:\Program Files\doxygen\bin;%ANT_HOME%\bin

Veljkov answered 19/1, 2013 at 2:22 Comment(1)
Running a command like '''where java''' which will list if java is in these other directories and taking priority over your JAVA_HOME path and which java is first. This might show which other path is messing with it. I've seen other java installs (JRE and JDK) place java also in ProgramData\Oracle and Windows\System32, so you can alternatively clean out java programs from these directories instead.Fawcette
C
4

The order of items in the PATH matters. If there are multiple entries for various java installations, the first one in your PATH will be used.

I have had similar issues after installing a product, like Oracle, that puts it's JRE at the beginning of the PATH.

Ensure that the JDK you want to be loaded is the first entry in your PATH (or at least that it appears before C:\Program Files\Java\jre6\bin appears).

Crackdown answered 5/2, 2012 at 19:42 Comment(0)
A
3

Make sure you use the root folder of the JDK. Don't add "\lib" to the end of the path, where tools.jar is physically located. It took me an hour to figure that one out. Also, this post will help show you where Ant is looking for tools.jar:

Why does ANT tell me that JAVA_HOME is wrong when it is not?

Adequacy answered 20/9, 2012 at 17:8 Comment(0)
D
2
  1. Try to check it once more according to this tutorial: http://vietpad.sourceforge.net/javaonwindows.html

  2. Try to reboot your system.

  3. If nothing, try to run "cmd" and type there "java", does it print anything?

Desdamonna answered 2/2, 2012 at 20:30 Comment(2)
It might be good to give a reflection on my answer. What have you tried?Desdamonna
I tried all of those, with no successSnobbery

© 2022 - 2024 — McMap. All rights reserved.