java.home is the JRE install directory, e.g.,
C:\jdk5\jre, or C:\Program Files\Java\jre1.5.0_06
. Unlike JAVA_HOME, I never seen java.home as an environment variable. java.home is a build-in Java system property, whose value is the JRE install directory. Since all Java system properties are also exposed as Ant build properties, you can also use ${java.home} in build files.Would jre.home be a better name? Maybe, but I don't think Sun will change it.
Therefore, java.home is always there inside JVM, whereas JAVA_HOME exists mainly in your shell environment and you may pass it to JVM as a system property. Why do we still need JAVA_HOME? Well, there are good reasons:
- You can add
$JAVA_HOME/bin
to the beginning of your PATH, to make sure you always invoke the right java program. On Windows, java.exe is duplicated in several places, for instance%JAVA_HOME%\bin\java.exe, $JAVA_HOME\jre\bin\java.exe, and %SystemRoot%\system32\java.exe
. Without have$JAVA_HOME/bin
at the beginning of the PATH, a java command will always resolve to%SystemRoot%\system32\java.exe
, which may not be what you want. The same problem can also exist in Linux/Solaris. - Some Java application runtime needs to use tools/libraries only available in JDK. For example, web containers need tools.jar in JDK to compile JSP pages, and ejb containers also need to invoke javac/rmic tools in JDK. So the build-in system property java.home is not sufficient.