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?

john
  • 903
  • 3
  • 9
  • 9
  • are you sure there are no classpath settings in ant folder? – kosa Feb 02 '12 at 20:30
  • Not that I can tell, but I might be missing something. What would I be looking for to find that? – john Feb 02 '12 at 20:33
  • 2
    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%. – Dhrumil Shah Mar 20 '13 at 10:32
  • 2
    Install JDK, Add new system variable "JAVA_HOME" to and add JAVA_HOME%\bin to system variable "path" – Mandeep Pasbola Jul 08 '14 at 09:48
  • 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. – pagurix Jan 31 '19 at 15:13

5 Answers5

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)

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
Jayan
  • 18,003
  • 15
  • 89
  • 143
  • 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. – john Feb 16 '12 at 21:05
  • 2
    ant expects 'JDK'. The java.exe from a JDK must be appear first. See comment from Mads Hansen – Jayan Feb 17 '12 at 07:53
  • 2
    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 issue – user1767260 Jan 18 '13 at 08:48
  • @ user1767260 : is that C:\Program Files (x86)\Java\jdk1.6.0_25 first entry in the path? – Jayan Jan 18 '13 at 08:56
  • No..but there is no entry for jre. – user1767260 Jan 18 '13 at 09:03
  • @ user1767260 : open command window and try 'where java'. – Jayan Jan 18 '13 at 09:07
  • C:\Windows\System32\java.exe C:\Program Files (x86)\Java\jdk1.6.0_25\bin\java.exe – user1767260 Jan 18 '13 at 09:12
  • Any idea?I am stuck in this iisue :( – user1767260 Jan 18 '13 at 10:25
  • 1
    The java.exe in system32 is a dummy: See http://mindprod.com/jgloss/javaexe.html#MULTIPLES. You can put your JDK/bin as the first entry. – Jayan Jan 18 '13 at 11:13
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

Mani
  • 1,364
  • 14
  • 33
Raj
  • 111
  • 1
  • 2
  • 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. – user1207381 Oct 17 '17 at 14:56
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).

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
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?

Community
  • 1
  • 1
Lou Morda
  • 5,078
  • 2
  • 44
  • 49
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?

Ondrej Kvasnovsky
  • 4,592
  • 3
  • 30
  • 40