Good evening. I have been searching all over the internet for this and have not had much luck. I was hoping to get an answer so that if anyone else has this question they can find it. Here is the situation I have set my JAVA_HOME and PATH variables accordingly


echo $PATH

I have tried setting JAVA_HOME to /usr/java/jdk/bin and a few other things that are not correct. From what I read this is the most correct as the bin directory has the javac library. Here is the problem whenever I run ant this is the error I see.

Unable to locate tools.jar. Expected to find it in /usr/lib64/jvm/java-1.6.0-sun-1.6.0/lib/tools.jar
Buildfile: build.xml

     [echo] Cleaning...

     [echo] Compiling...
    [javac] Compiling 1 source file to /home/jonw/programming/anttest

/home/jonw/programming/anttest/build.xml:7: Unable to find a javac compiler; is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib64/jvm/java-1.6.0-sun-1.6.0/jre"

Total time: 0 seconds

As can be seen first it cannot find the tools jar. The worst is that later on it tells me that JAVA_HOME is set to something that I have NOT set JAVA_HOME to. I have tried to uninstall this version but it just reverts to some other version rather than the one I specify. Why is this? How do I fix it? I would really like to know why ant takes it upon itself to choose a version other than the one I have specified?

Any help will be greatly appreciated.


The Quick Java Switch and Fix

Thank you for your quick answer. The above suggestion was already done. The programs I try to build do not run on openJDK. The version of the jdk that I have is the one downloaded from Oracle’s website. It is valid, and JAVA_HOME points correctly to it. The only program that does not respect this system variable, $JAVA_HOME is ant.

It’s probably the ant script that’s setting JAVA_HOME to something you don’t want. Edit the script and comment out the setting to inherit the system settings, or modify it to point to where you want.


have a look at this :

Running ant tasks that use the JDK - Maven User - Codehaus

referenced from here :

ant - JAVA_HOME gets mangled by Maven - Stack Overflow

As Ken-Yap said, it’s probable that the ant script sets the java_home to something else.



I would like to thank everyone for their help. I am happy to tell you that this has been resolved. I looked into the ant script and found that if I turned the no_config=true it would use the right java_home but other paths were messed up so I decided to find what that option changed and found that when set to true it would use the /etc/ant.conf for some configuration changes. I looked in there and sure enough there was the offending line of code. This is what my ant.conf looks like now just in case it might help someone with the same problem

# ant.conf (Ant 1.7.x)
# JPackage Project <>

# Validate --noconfig setting in case being invoked
# from pre Ant 1.6.x environment
if  -z "$no_config" ] ; then

# Setup ant configuration
if $no_config ; then
  # Disable RPM layout
  # Use RPM layout

  # ANT_HOME for rpm layout

Again thanks for your help.