ingyhere ingyhere - 4 months ago 6x
Java Question

Where does Ant set its 'java.home' (and is it wrong) and is it supposed to append '/jre'?

Okay, I'm using Ant version 1.7.1 (default install) on CentOS 6.3:

[theuser@dev-ingyhere ~]$ ant -version
Apache Ant version 1.7.1 compiled on August 24 2010
[theuser@dev-ingyhere ~]$ cat /etc/*-release
CentOS release 6.3 (Final)

I have
set and I run

[theuser@dev-ingyhere ~]$ export JAVA_HOME=/usr/java/jdk1.7.0_17 ; echo $JAVA_HOME ;
[theuser@dev-ingyhere ~]$ ant -diagnostics | grep java\\.home
java.home : /usr/java/jdk1.7.0_17/jre

This is even more fun:

[theuser@dev-ingyhere ~]$ export JAVA_HOME=/a/fools/folly ; echo $JAVA_HOME ; ant -diagnostics | grep java\\.home
java.home : /usr/java/jdk1.7.0_17/jre
[theuser@dev-ingyhere ~]$ env | grep JAVA

So, I do get one thing -- apparently Oracle's Java 7 Javadoc for Class System is WRONG (aghast!) where it describes the
System Property as the "Java installation directory." I know that because the Java(TM) Tutorials for System Properties describes the
System Property as the "Installation directory for Java Runtime Environment (JRE)." In other words the
in the environment does not necessarily equal
in the JVM System Properties. (What sets that?!)

QUESTION: Where and how does
get/set the system property


Really a JVM internals question

Since Ant is just echoing the java.lang.System properties (see comment above under original post), this is really a JVM question. The Java HotSpot Virtual Machine is the core interpreter. Code is available online at

On line 309 of the C++ code for HotSpot (os_linux.cpp) there is a an init_system_properties_values() method in the os class. It does some mild heuristics to kind of sniff out the location for a variable named home_path which ends up being set to what Java users see as "java.home". Comments in the code indicate that '<java_home>/jre' is being formally specified as the java.lang.System property value for "java.home" (in the case of a JDK install).