2

I am trying to install Apache Ant on my system, while setting the path variable. I have jdk installed on my system. I set the ANT_HOME environment variable to where ant is located on the system, i.e, F:\apache-ant-1.9.6\, and the path variable to F:\apache-ant-1.9.6\bin.

path variable ANT_HOME variable

But when I test if ANT is installed correctly by typing ant -version on cmd , I get this error:

Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.8.
0_25\lib\tools.jar
Apache Ant(TM) version 1.9.6 compiled on June 29 2015

While reading this answer, they say tools.jar in included in jdk and not jre. But I have correctly installed jdk, and set the environment variable correctly for that too.

Community
  • 1
  • 1
Aman Grover
  • 1,621
  • 1
  • 21
  • 41

4 Answers4

3

When you actually go to the location specified by ant build it'll not have tools.jar. The error is misleading and wrong. It is just because either JAVA_HOME is not defined or not set properly. Once it is done, error would get resolved.

Yeshwanth N
  • 570
  • 4
  • 15
2

I was also facing same issue but after research of an 1 hour I got a solution.

  1. In system variable set your jdk path in starting.
  2. Variable name: Path
  3. Variable value: C:\ProgramFiles\Java\jdk1.8.0_45\bin;C:\Users\SESA401780\AppData\Local\Android\sdk\build-tools;C:\Users\SESA401780\AppData\Local\Android\sdk\tools;...

  4. Enter Ok Ok ... and

  5. Open new cmd
bummi
  • 27,123
  • 14
  • 62
  • 101
siddhartha shankar
  • 1,450
  • 13
  • 16
1

You are most likely missing the JAVA_HOME environment variable. It looks like the java.exe you are running from the command line is finding your JRE, not your JDK. Set JAVA_HOME to the location of your JDK, and move the bin directory of your JDK to be before the JRE in your PATH and try again, should work.

Brad Peabody
  • 10,917
  • 9
  • 44
  • 63
  • But the java programs are compiling and executing correctly , I have been compiling java programs from the past 1 year. If the JAVA_HOME variable is not correctly set , how come java programs run fine? – Aman Grover Aug 29 '15 at 17:05
  • Most likely because javac.exe (not java.exe) is being found from the JDK and that works properly. But when something (ant.bat I believe) is invoking java.exe it's running a different executable from a different folder (from the JRE) and thus not finding tools.jar automatically. – Brad Peabody Aug 29 '15 at 17:08
  • okay , I have tried to set the java path and the ant path again, deleting the old ones , still getting the same error. – Aman Grover Aug 29 '15 at 17:14
0

As the error message says:

Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.8.
0_25\lib\tools.jar

tools.jar is expected to be in C:\Program Files\Java\jre1.8, but it's not there. That path looks suspiciously like a JRE path, not a JDK.

Make sure to set JAVA_HOME to the path of your JDK. Then it should work. It seems that currently JAVA_HOME is pointing to the path of the JRE, not the JDK.

janos
  • 120,954
  • 29
  • 226
  • 236
  • But I have set the JAVA_HOME variable to jdk and not jre, still getting this strange error – Aman Grover Aug 29 '15 at 17:15
  • 1
    Just to get things clear, please confirm this: on the command line, when you do `echo %JAVA_HOME%`, it prints the path to JDK. And then when you do `ant -version` it prints an error message about expected `tools.jar` in `C:\Program Files\Java\jre1.8. 0_25`, which is different from the JDK path. Right? – janos Aug 29 '15 at 21:10