I came across this oldish thread while trying to resolve the same
problem:

David Nemer wrote:
> I am running ANT programmatically in JAVA. So, my task is to build the
> BUILD.XML.
> I'm able to do so, but it throws an exception saying:
>
> /scratch2/nemer/test/xfire/build.xml:5: The following error occurred while
> executing this line:
> /scratch2/nemer/test/xfire/build-common.xml:81: 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 "/opt/jdk1.6.0_06/jre"


I think I have found an explanation on what is going on, at least
for cases where ant is run using a shell script on the command line.


Environment:
Linux (Slackware)
Java is Sun JDK 1.6.0_17-b04, from Slackware packages

build.xml for the test:
<project>
  <echo message="JAVA_HOME: ${java.home}"/>
</project>

Environment variables, executable locations:
bash-3.1$ echo $JAVA_HOME
/usr/lib64/java
bash-3.1$ echo $PATH
/usr/lib64/java/bin:/usr/bin:/bin:/home/jlaiho/aa/apache-ant-1.7.1/bin
bash-3.1$ type -a ant
ant is /home/jlaiho/aa/apache-ant-1.7.1/bin/ant
bash-3.1$ type -a java
java is /usr/lib64/java/bin/java

The installation pointed to by JAVA_HOME is a JDK installation
(tools.jar does exist in $JAVA_HOME/lib). A JRE installation
also exists, at $JAVA_HOME/jre .

bash-3.1$ ls -l /usr/lib64/java/lib/tools.jar
-rw-r--r-- 1 root root 12590684 2009-11-05 23:08 /usr/lib64/java/lib/tools.jar

Running the test:
bash-3.1$ ant
Buildfile: build.xml
     [echo] JAVA_HOME: /usr/lib64/java/jre

BUILD SUCCESSFUL
Total time: 0 seconds

What happened? Explanation can be found in the ant shell script,
starting at line 125 (at which point there hasn't been anything
that would set JAVACMD):

if [ -z "$JAVACMD" ] ; then
  if [ -n "$JAVA_HOME"  ] ; then
    # IBM's JDK on AIX uses strange locations for the executables
    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
      JAVACMD="$JAVA_HOME/jre/sh/java"
    elif [ -x "$JAVA_HOME/jre/bin/java" ] ; then
      JAVACMD="$JAVA_HOME/jre/bin/java"
    else
      JAVACMD="$JAVA_HOME/bin/java"
    fi
  else
    JAVACMD=`which java 2> /dev/null `
    if [ -z "$JAVACMD" ] ; then
        JAVACMD=java
    fi
  fi
fi

... so, as JAVACMD was empty, and JAVA_HOME was set, AND
$JAVA_HOME/jre/bin/java did exist, then the JAVA_HOME was
forcible overridden with the JRE home directory. I don't
understand why, but that is what happens.

Is this a bug - perhaps? At least it's not what I would
expect.
--
..Juha


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Reply via email to