When trying to compile a Javadoc taglet, which requires $JAVA_HOME/lib/tools.jar
, I discovered that ant (version 1.8.4) sets java.home
to $JAVA_HOME/jre
rather than just $JAVA_HOME
. I verified this thusly:
<echo>${java.home}</echo>
<echo>${env.JAVA_HOME}</echo>
[echo] /usr/java/jdk1.7.0_21/jre
[echo] /usr/java/jdk1.7.0_21
According to ant -diagnostics
, there isn't any property like a jdk.home
. Thus, to use tools.jar
I have to do:
<classpath location="${java.home}/../lib/tools.jar"/>
So, I have two questions:
1) Is there something wrong with my setup of ant that's causing java.home
to point to the JRE instead of the JDK?
2) If this is the way ant is supposed to work, is using the ..
in my classpath the way I'm supposed to do things? Or should I do ${env.JAVA_HOME}/lib/tools.jar
? Or something else entirely?
Set the JAVA_HOME System Variable Click the Advanced tab, and then click Environment Variables. Under System Variables, look for the JAVA_HOME system variable. The JAVA_HOME path should point to the location that you recorded when you installed the JRE.
No. Traditionally, JAVA_HOME is set to the JRE or SDK main directory. The bin/ subdirectory might be in your PATH, though.
JAVA_HOME is an operating system (OS) environment variable which can optionally be set after either the Java Development Kit (JDK) or the Java Runtime Environment (JRE) is installed. The JAVA_HOME environment variable points to the file system location where the JDK or JRE was installed.
Here are the answers:
"Is there something wrong with my setup ...?" No. Ant is setting it's internal java.home based on JVM System properties. The code for HotSpot (JVM internals) sets it with "/jre" appended on purpose. In fact, the Java(TM) Tutorials for System Properties describes it exactly that way. The "java.home" variable from inside ant really isn't one-in-the-same as the "JAVA_HOME" that is set in your environment -- different but with similar names.
"(What is) the way I'm supposed to do things?" You can really do whatever you feel is appropriate, but remember that Ant can and usually does run in a separate JVM process. I'd assume that your system environment is probably specifying the JVM that was used to develop the app, so I would just use "${env.JAVA_HOME}" to ensure that development expectations meet build expectations.
For more information, please see another similar answer here.
Also, consider that more info can be collected from ant by running it with the -debug, -diagnostics and/or -verbose flags.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With