Return-Path: Delivered-To: apmail-ant-user-archive@www.apache.org Received: (qmail 32493 invoked from network); 21 Dec 2009 18:26:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 Dec 2009 18:26:39 -0000 Received: (qmail 48748 invoked by uid 500); 21 Dec 2009 18:26:38 -0000 Delivered-To: apmail-ant-user-archive@ant.apache.org Received: (qmail 48653 invoked by uid 500); 21 Dec 2009 18:26:38 -0000 Mailing-List: contact user-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list user@ant.apache.org Received: (qmail 48643 invoked by uid 99); 21 Dec 2009 18:26:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Dec 2009 18:26:37 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00 X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [195.156.147.13] (HELO kirsi2.inet.fi) (195.156.147.13) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Dec 2009 18:26:29 +0000 Received: from mail.ichaos-int (88.195.115.158) by kirsi2.inet.fi (8.5.014) id 4B17EFA600CFB764 for user@ant.apache.org; Mon, 21 Dec 2009 20:26:07 +0200 Received: from [192.168.105.13] (mail.ichaos-int [192.168.105.13]) by mail.ichaos-int (Postfix) with ESMTP id 4ECA562F29 for ; Mon, 21 Dec 2009 20:26:07 +0200 (EET) Message-ID: <4B2FBDBE.5050204@iki.fi> Date: Mon, 21 Dec 2009 20:26:06 +0200 From: Juha Laiho User-Agent: Thunderbird 2.0.0.23 (X11/20090820) MIME-Version: 1.0 To: user@ant.apache.org Subject: Re: Java in JDK but ANT can't find it! Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 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-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org