17
votes

I'm trying to use ant in a vista 64 environment to build some docbook/xml files.

However, I can't resolve this error message. Anybody have suggestions?

C:\Users\Robert Admin>ant Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\li b\tools.jar Buildfile: build.xml does not exist! Build failed

Googling around, I see that this tools.jar message is the result of ant not being able to find the jdk. In fact, C:\Program Files\Java\jre6\li b\tools.jar is a JRE installed with another program (I'm guessing). Tools.jar is located here: C:\Program Files\Java\jdk1.6.0_22\lib

I can't seem to tell Ant to look in the JDK path, only the JRE path which was already there. (Judging from the Ant documentation, it seems that JRE is insufficient).

C:\Users\Robert Admin>echo %JAVA_HOME%

C:\Program Files\Java\jdk1.6.0_22\bin

C:\Users\Robert Admin>ant

Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\li
b\tools.jar
Buildfile: build.xml does not exist!
Build failed

C:\Users\Robert Admin>echo %ANT_HOME%

I:\My Documents\1latest\ant    
C:\Users\Robert Admin>where java

C:\Windows\System32\java.exe
C:\Program Files (x86)\Java\jre6\bin\java.exe
C:\Program Files\Java\jdk1.6.0_22\bin\java.exe

C:\Users\Robert Admin>java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)

Update #1. I tried uninstalling the 64 bit jdk and installing the 32 bit jdk. Result:

C:\Users\Robert Admin>java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)

C:\Users\Robert Admin>ant
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\li
b\tools.jar
Buildfile: build.xml does not exist!
Build failed
C:\Users\Robert Admin>echo %JAVA_HOME%
C:\Program Files (x86)\Java\jdk1.6.0_22\bin
14
Just make jdk...\bin appear in Path before jre6\bin.khachik
I removed the reference to jre6\bin in the PATH system variable. There is now only one java reference in my path system variable. Same results. Note that there QTJAVA and CLASSPATH both reference .;C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip but that seems like something which wouldn't conflict.idiotprogrammer

14 Answers

6
votes

I had this problem on a 64-bit Windows 7 machine and Ant 1.8.2. The solution was to use the admin tools mentioned by #bigfix to set the environment variables. Follow the Ant installation instructions for Windows. But do not set the path as %ANT_HOME%\bin. Instead, use an explicit path such as C:\jdk-1.5.0.05\bin.

My first test failed because my command window was already open and using the old env vars. Close it and open a new one. Then try the test. It worked for me.

20
votes

I had the same problem because my JAVA_HOME path was set incorrectly (just like the OP's). It was set to the bin of the jdk.

So it was set to: C:\Program Files (x86)\Java\jdk1.6.0_25\bin

When it should have been set to: C:\Program Files (x86)\Java\jdk1.6.0_25

Updating this environmental variable fixed it for me.

6
votes

I fixed this by creating JAVA_HOME in computer-> properties-> env variables Manual setup in command line did not work -b

6
votes

I solved the problem by creating system variable JAVA_HOME to C:\Program Files\Java\jdk1.6.0_25. Don't put the semi colon after it. First of all I put the semi colon and there was an error. I removed the semi colon and it worked.

5
votes

All you need is to set JAVA_HOME path in your environment. In Windows 7 go to "System Properties -> Advanced -> Environment Variables" and add JAVA_HOME. The value in my case was:

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

This resolved the issue for me. This variable points Ant to the correct Java location.

4
votes

I know this thread is some what old..but i faced it just now too..what i did was copy that tools.jar into jre/lib folder and worked fine.

I'm in Windows 7 , JDK 1.7 environment and trying to install ant 1.8.2

Thanks

3
votes

you may be using the java in the C:\Windows\system32 directory rather then the installed JDK. I set a JAVA_HOME environmental variable and put %JAVA_HOME%\bin at the start of my path and the problems when away.

2
votes

why don't you try the 32 bit version. there could be a problem between the two versions you have installed being 32 and 64. try the 32 bit version so ur not seeing any 64 bit versions.

it should fix ur problem.

1
votes

I had this issue with Environment as :

  • Windows 7
  • Java version jdk1.6.0_33
  • apache-ant-1.6.5

I Was getting ant build message as "Unable to locate tools.jar. Expected to find it in E:\Java\jre6\lib\tools.jar", where my JDK was installed at E:\Java\jdk1.6.0_33\ and JRE at E:\Java\jre6\

Cause:

My issue was that I have ANT_HOME was set twice in the PATH system Environment variable at two different places (means some other variables in between).

Solution:

I removed the ANT_HOME variable that pointed to the wrong location and everything worked fine with me.

0
votes

I once faced the same problem of ant setup. The promotion is just the same as

Unable to locate tools.jar`. Expected to find it in C:\Program Files\Java\jre6\li b\tools.jar 
Buildfile: build.xml does not exist! Build failed. 

I deleted all jre path in %PATH% environment and add jdk bin path. Finally I type %ANT_PATH%/bin instead of %ANT_PATH%\bin. It works.

May help.

0
votes

I got the same issue. Successfully resolved.

  1. Check your systeminformation that jenkins see : your_jenkins_url/systemInfo
  2. Look for "JAVA_HOME" variable in the "Environment Variables" section. In my case I was not able to found it.

So if you do not see this variable it means that your variable was not set for the user that jenkins run under. You need to put "JAVA_HOME" in to the "system variables" section of environment variables, not "user variables".

restart jenkins after this and your problem must be fixed.

0
votes

I was getting a "C:\Program" is not recognized as an internal or external command, operable program or batch file error, when running %ANT_HOME%\bin\ant.bat

I found that I needed to wrap the command in double-quotes in order to get the proper escaping to happen on the path string.

FIX: "%ANT_HOME%\bin\ant.bat" --NOT-- %ANT_HOME%\bin\ant.bat

Hope that helps!

0
votes

Thanks, this also works on Windows 8, x64, using Java x64.

I didn't want to add all that junk to my system settings so I created a batch file that I'd run just before I wanted to use the Android SDK. Here it is

    set ANDROID_SDK_PT=C:\Program Files\eclipse\sdk\platform-tools
    set ANDROID_SDK_TOOLS=C:\Program Files\eclipse\sdk\tools
    set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_25
    set ANT_HOME=C:\apache-ant
    set PATH=%PATH%;%ANDROID_SDK_PT%;%ANDROID_SDK_TOOLS%;%JAVA_HOME%;%ANT_HOME%\bin
0
votes

I am going to add one other issue that I had with this.

BTW, the answer here worked for me too. I had to point my java directory to the specific SDK version. Thank you very much.

But I'm going to add that I had to install the SDK as an administrator, or it didn't extract tools.jar. I found this answer elsewhere, and I hope it helps someone to repeat it here.