2

I am using windows 7 java installed in Program files and Program Files (x86). I am getting such error "Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre7\lib\tools.jar

 I have set path variable to `C:\Program Files\Java\jdk1.7.0_51;`
 JAVA_HOME `C:\Program Files\Java\jdk1.7.0_51;`

But I tried ant -diagnostics command get java.home is C:\Programe Files\Java\jre7\

Koushik Rout
  • 179
  • 1
  • 4
  • 12
  • Did you set the environment variables locally (to the console session) or via the System Properties dialog? If you used the System Properties dialog, did you close and re-open the console and try again? What does `echo %java_home%` display? – MadProgrammer Jun 26 '14 at 07:14
  • via system properties, and yes I am trying ant command by closing command prompt. `echo %java_home%` display `C:\Program Files\Java\jdk1.7.0_51;` – Koushik Rout Jun 26 '14 at 07:19
  • 1
    I hope you set %PATH% to `%JAVA_HOME%\bin`, rather than just to `%JAVA_HOME%` as there are no binaries in `%JAVA_HOME%`, which could lead to what you're seeing – Anya Shenanigans Jun 26 '14 at 07:51
  • @KoushikRout Can you attach a screenshot of the output on the console for echo %JAVA_HOME% please? – JamesB Jun 26 '14 at 08:10
  • possible duplicate of [Unable to locate tools.jar](http://stackoverflow.com/questions/5730815/unable-to-locate-tools-jar) – Mark O'Connor Jun 29 '14 at 08:34
  • Add %JAVA_HOME%\bin to the system variable "path" – Mandeep Pasbola Jul 08 '14 at 09:44

2 Answers2

0

If you have installed Java Development Kit (JDK) you can find this Jar at the place.

I seems you have installed only Java Runtime Environment (JRE)

So if tools.jar is not there at the path C:\Program Files\Java\jre7\lib\, try placing it manually at the path.It should solve your problem.

Ninad Pingale
  • 6,801
  • 5
  • 32
  • 55
  • In Program files\Java folder both jdk1.7.0.51 and jre7 folder are there so I think jdk installed properly. – Koushik Rout Jun 26 '14 at 07:23
  • Manually place tool.jar at C:\Program Files\Java\jre7\lib\ – Ninad Pingale Jun 26 '14 at 07:26
  • Yes I manually place tool.jar at proper place it works for me but is this the actual solution or I need to try some other way ? – Koushik Rout Jun 26 '14 at 07:32
  • Moving tools.jar to the JRE lib folder is definitely not the solution here. – JamesB Jun 26 '14 at 07:35
  • He has both JDK and JRE installed..And Tool.jar is doesn't exists because of some reason, so I suggested that..Why wont it be a solution if the error goes away by manually placing it there ? – Ninad Pingale Jun 26 '14 at 07:40
  • Perhaps investigate the reason why it isn't there? Your proposal is a workaround, not a solution – JamesB Jun 26 '14 at 07:52
  • Ok.Then one more try can be add %JAVA_HOME% to start of the PATH variable. – Ninad Pingale Jun 26 '14 at 07:53
  • Now you are guessing. You always add %JAVA_JOME%\bin to PATH anyhow. – JamesB Jun 26 '14 at 07:55
  • @JavaLearner So what happens if the JDK is re-installed? The problem will exist once again unless someone remembers the manual step to copy the tools.jar file again. Like I say, not a solution, a temporary workaround at best. – JamesB Jun 26 '14 at 08:11
0

I had the same issue.

echo %JAVA_HOME%:

C:\Program Files\Java\jdk1.8.0_51

But ant -diagnostics indicated:

java.home : C:\Program Files\Java\jre1.8.0_60

The problem is the JAVA_HOME environment variable is pointing to an invalid directory.

In your case, C:\Program Files\Java\jdk1.7.0_51 does not exist, so Ant goes looking for the folder itself and I guess pulls the JRE folder first.

The problem is that C:\Program Files\Java\jdk1.7.0_51 does not exist, and so ANT resets the java.home variable to first Java directory that it finds:

C:\Programe Files\Java\jre7\

In my case, I had both of these and it still did not find the correct one:

C:\Program Files\Java\jdk1.8.0_60

C:\Program Files\Java\jre1.8.0_60

You probably had updated to a more recently version of the JDK, like

C:\Program Files\Java\jdk1.7.0_79

Keith Davis
  • 351
  • 5
  • 14