Ant JAVA_HOME Issue

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 $JAVA_HOME
/usr/java/jdk

echo $PATH
/usr/lib64/mpi/gcc/openmpi/bin:/home/jonw/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games::/usr/java/jdk/:/usr/java/jdk//bin:/usr/java/jdk/bin

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

clean:
     [echo] Cleaning...

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

BUILD FAILED
/home/jonw/programming/anttest/build.xml:7: Unable to find a javac compiler;
com.sun.tools.javac.Main 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.

Jon

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.

Hi,

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.

HTH

Lenwolf

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 <http://www.jpackage.org/>

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

# Setup ant configuration
if $no_config ; then
  # Disable RPM layout
  rpm_mode=false
else
  # Use RPM layout
  rpm_mode=true

  # ANT_HOME for rpm layout
  ANT_HOME=/usr/share/ant
  JAVA_HOME=/usr/java/latest/
fi

Again thanks for your help.

Jon