How do I change the JAVA_HOME for ant?

喜欢而已 提交于 2019-12-03 09:26:33

You could create your own script for running ant, e.g. named ant.sh like:

#!/bin/sh
JAVA_HOME=</path/to/jdk>; export JAVA_HOME
ant $@

and then run your script.

$ chmod 755 ant.sh
$./ant.sh clean compile

or whatever ant target you wish to run

JAVA_HOME should point at where the JDK is installed not not a JRE.

So, if you type ls $JAVA_HOME what do you see? if you do ls $JAVA_HOME/bin/ do you see javac?

If the first doesn't work then you don't have JAVA_HOME pointing at the right directory. If the second doesn't work then you need to point JAVA_HOME at a JDK instead of a JRE.

Looking at the shell script for invoking ant, it is possible that the value for $JAVA_HOME set for your shell in .bashrc can be overridden in the files /etc/ant.conf, $HOME/.ant/ant.conf, and $HOME/.antrc. If you execute bash -x <path to ant script> it will emit debugging information which should help you track down where $JAVA_HOME is being overridden.

klana

On my Windows 7 machine setting:

JAVA_HOME="C:\Program Files\Java\jdk1.6.0_18" 

didn't work. But setting:

JAVA_HOME=C:\Program Files\Java\jdk1.6.0_18

worked.

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

Niranjan Sarvi

Though the environment variable JAVA_HOME set correctly, the ant may use the configured JRE within the each build.xml or any build files.

To check what version of the JRE the ant is using, right click on the build file -> select the build ant which displays the details about the tasks to choose etc, select the JRE which you want to use.

Its advisable to use the project level settings or just at the workspace level.

There are 2 ways of changing the compiler:

  • export JAVA_HOME=/path/to/jdk before you start Ant.
  • Set <javac exectuable="/path/to/javac">

Another option would be to add a respective tools.jar to the classpath, but that path is usually taken if Ant is started from another tools like Maven.

Fore more details on these (or other) options of changing Java Compiler in Ant, see this article for example.

JAVA_HOME needs to point to a JDK home if you're trying to compile code. Check to see if '/usr/tomcat/jre/bin/javac' exists. I doubt it does.

If you don't have a JDK, then you can work around it by getting the ECJ (eclipse compiler) library, dropping it into '~/.ant/lib' and adding a system property to the command-line to use that compiler - check the Ant manual for details.

http://ant.apache.org/

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.

cdecker

When using Bash just try this:

$ export JAVA_HOME=/usr/tomcat/jre

You will need to change JAVA_HOME path to the Java SDK directory instead of the Java RE directory. In Windows you can do this using the set command in a command prompt.

e.g.

set JAVA_HOME="C:\Program Files\Java\jdk1.6.0_14"

try with this:

/usr/sbin/update-alternatives --config java

When running ant from the shell, you don't need to export JAVA_HOME first, which would set that variable for your current shell and all future commands, instead use

user@host:~# JAVA_HOME=/path/to/jdk ant targets
jean

java_home always points to the jdk, the compiler that gave you the classes, and the jre is thw way that your browser or whatever will the compiled classes so it must have matching between jdk and jre in the version.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!