Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 393
john Avatar asked Feb 02 '12 20:02

john


People also ask

Can not determine path to Tools jar?

The problem is with version of JDK you are using. The Intellij version 2020.2 supports only upto JDK 14. So either you have to lower the JDK version to 14 or update the IntelliJ to a newer version like 2021.

Where can I find tools jar in JDK?

Ant expects the tools. jar file to be in the %JAVA_HOME%/lib but tools. jar is distributed with the JDK.

What is the use of tools jar in java?

The jar tool combines multiple files into a single JAR archive file. jar is a general-purpose archiving and compression tool, based on ZIP and the ZLIB compression format. However, jar was designed mainly to facilitate the packaging of java applets or applications into a single archive.

What is RT jar?

1. rt. jar stands for runtime and contains all of the compiled class files for the core Java Runtime environment. 2) You must include rt. jar in your classpath, otherwise you don't have access to core classes e.g. java.


2 Answers

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)

like image 188
Jayan Avatar answered Oct 03 '22 14:10

Jayan


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

like image 37
Raj Avatar answered Oct 03 '22 16:10

Raj