Alex Rivera | Logout

How do I change the JAVA_HOME for ant?

Asked 2009-02-21T15:39:26.077
33

I'm doing java work on a class server where I don't have root. Whenever I try to compile using ant, it points to the wrong directory (/usr/tomcat instead of /usr/tomcat/jre ).

One of the things we were told to do when setting up our user accounts was to add export JAVA_HOME=/usr/tomcat/jre to the .bashrc file. I don't know if that was supposed to take care of the problem but it doesn't seem to.

So, how can I change the JAVA_HOME property for ant but only for when I run ant?

EDIT: echo $JAVA_HOME points to /usr/tomcat/jre echo $JAVA_HOME\bin points to /usr/tomcat/jrebin

The problem is when I normally run ant I get this error:

Unable to locate tools.jar. Expected to find it in /usr/tomcat/lib/tools.jar
Buildfile: build.xml

compile:
    [javac] Compiling 1 source file to /home/ejm244/build/classes

BUILD FAILED
/home/ejm244/build.xml:9: 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

Total time: 0 seconds
Edit
Report

3 Answers

3

Set the env var: JAVACMD - full path of the Java executable. Use this to invoke a different JVM than JAVA_HOME/bin/java(.exe).

Reference: http://ant.apache.org/manual/running.html

answered 2012-01-25T12:22:44.567
1

When using Bash just try this:

$ export JAVA_HOME=/usr/tomcat/jre
answered 2009-02-22T03:35:03.580
1

Set the JRE in the project (project properties -> Java Build Path-> Libraries, typically last entry), or global default in preferences (Java->Installed JREs) to a JDK, not a JRE.

answered 2010-10-06T13:30:19.350

Your Answer