Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ant ${java.home} points to $JAVA_HOME/jre, not $JAVA_HOME

Tags:

ant

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?

like image 983
Matthew Cline Avatar asked Jul 03 '13 00:07

Matthew Cline


People also ask

Can we set JAVA_HOME to JRE?

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.

Does JAVA_HOME need to point to bin?

No. Traditionally, JAVA_HOME is set to the JRE or SDK main directory. The bin/ subdirectory might be in your PATH, though.

What is JAVA_HOME supposed to point to?

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.


1 Answers

Here are the answers:

  1. "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.

  2. "(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.

like image 81
ingyhere Avatar answered Sep 24 '22 03:09

ingyhere