4

I just installed the latest JDK 7 Update 21 and wrote the following one-liner (on Windows 7):

public static void main(String[] args) {
    System.out.println("java.home = " + System.getProperty("java.home"));
}

the output is (surprisingly):

java.home = D:\Java\jdk1.7.0_21\jre

I believe I fixed all the common causes:

  1. JAVA_HOME is set to "D:\Java\jdk1.7.0_21"
  2. I have set "D:\Java\jdk1.7.0_21\bin" as the first path in the system PATH setting.
  3. There is no java.exe in Windows\System32
  4. I am using a "fresh" command-line
  5. I have searched this and other sites extensively
  6. My registry does not contain a "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment" key. The value of "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.7" contains a correct "JavaHome" value.
  7. Adding "-server" option to the java.exe call does not change the output

Here is some more output for your information

D:\Temp>echo %PATH%
d:\Java\jdk1.7.0_21\bin

D:\Temp>echo %JAVA_HOME%
D:\Java\jdk1.7.0_21

D:\Temp>type SystemInfo.java
public class SystemInfo {

        public static void main(String[] args) {
                System.out.println("java.home = " + System.getProperty("java.home"));
        }

}

D:\Temp>java -verbose SystemInfo
[Opened d:\Java\jdk1.7.0_21\jre\lib\rt.jar]
[Loaded java.lang.Object from d:\Java\jdk1.7.0_21\jre\lib\rt.jar]
[Loaded java.io.Serializable from d:\Java\jdk1.7.0_21\jre\lib\rt.jar]
...
[Loaded java.lang.Void from d:\Java\jdk1.7.0_21\jre\lib\rt.jar]
java.home = d:\Java\jdk1.7.0_21\jre
[Loaded java.lang.Shutdown from d:\Java\jdk1.7.0_21\jre\lib\rt.jar]
[Loaded java.lang.Shutdown$Lock from d:\Java\jdk1.7.0_21\jre\lib\rt.jar]

(Updated:) Basically I need to know, how to run my java application so that it has access to the java-compiler (found in the JDK's tools.jar) without copying that JAR to some other place.

BTW the main problem behind this is that my jetty can't compile a JSP since the java-compiler is missing. I know I can add "tools.jar" to JRE\lib\ext but thats not a long-term solution.

Tom
  • 1,739
  • 2
  • 21
  • 31
  • 1
    The java.home should point to the runtime, that's simply the runtime used to execute the program. It is unrelated to the JAVA_HOME variable, the installer does not even set that. Whatever problem you are having, it is not related to the java.home property. – Gimby Jun 12 '13 at 09:20
  • Do you use any kind od IDE for your example one-liner? – Dominic Weiser Jun 12 '13 at 09:25
  • TooR -- no, powered by "notepad.exe" ;) – Tom Jun 12 '13 at 09:37

2 Answers2

7

This is by default -- specified in the C++ code of the Java HotSpot interpreter. Also, it is what Sun originally wanted the System Property to set when the environment's Java home points to a JDK.

See the Java(TM) Tutorials for System Properties where it describes the java.home System Property as the "Installation directory for Java Runtime Environment (JRE)." Also, note that Oracle's Java 7 Javadoc for Class System is WRONG (aghast!) where it describes the java.home System Property as the "Java installation directory."

The answer lies on line 309 of the actual JVM code!

Neeme Praks
  • 8,150
  • 5
  • 40
  • 46
ingyhere
  • 8,842
  • 3
  • 28
  • 41
0

It's perfectly fine what you see as output - it's your default Java execution environment.

In order to configure jetty to use your JDK, maybe this helps.

Alexander Rühl
  • 6,369
  • 7
  • 45
  • 94