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:
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.
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!
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