4
votes

I am using Windows 7 x64 and I'm trying to install Apache Ant. I'm always get the following error message:

C:\Users\xxx>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

In various forums they say that the environment variables are not set correctly. I set them as following on my system:

ANT_HOME: C:\Ant

CLASSPATH: C:\Program Files\Java\jdk1.6.0_21\bin

JAVA_HOME: C:\Program Files\Java\jdk1.6.0_21\bin

Path: (...many things...);C:\Program Files\Java\jdk1.6.0_21\bin;C:\ant\bin;%JAVA_HOME%\bin;

But I am still getting the error. Do you know how to force ant to use the correct directory? Java (both JRE and JDK) appear in Program Files and Program Files (x86). And seems trying to use the 64x JRE.

5

5 Answers

5
votes

JAVA_HOME should be C:\Program Files\Java\jdk1.6.0_21\ (drop the "bin") and tools.jar is going to be in lib, not bin.

1
votes

Check the "many things" path - one of those likely has a java executable in it.

1
votes

In the (...many things...) area do you have a path to the JRE? Try removing it. Also, instead of using %JAVA_HOME% in your path, you can try setting the full path (thought it should work, I have had issues before).

Lastly for JAVA_HOME, remove the \bin

0
votes

I know this is an old post, but a link to this post here:

http://ant.apache.org/manual/

It is claiming that to not set the classpath because Ant could break things from the confusion. If this was to occur then the following should be added to ignore it:

<property environment="env."/>
<property name="env.CLASSPATH" value=""/>
<fail message="Unset $CLASSPATH / %CLASSPATH% before running Ant!">
    <condition>
        <not>
            <equals arg1="${env.CLASSPATH}" arg2=""/>
        </not>
    </condition>
</fail>

Hopefully any of this helps in case someone stumbles across this like I have.

0
votes

I know this is an old post but followind did the trick for me in JAVA_HOME replace "Program Files" -> "Progra~1"