Difference between java.home and JAVA_HOME

前端 未结 2 1105
渐次进展
渐次进展 2020-12-10 03:58

In my java code, I have this line System.getProperty(\"java.home\"). In some environments, this returns the same value as what has been set JAVA_HOME

2条回答
  •  不思量自难忘°
    2020-12-10 04:51

    As you stated, JAVA_HOME points to the JDK installation path given by the Environment Variable(%JAVA_HOME%).

    But java.home points to the JRE installation path, now it returns the JRE that was used to run the application, please remember that you can have multiple versions of JRE and JDK on the same server/computer

    And you can run an application specifying what jre or jdk you want to use.

    So, for example, if you have on your Environment path:

    %JAVA_HOME% = C:\Program Files\Java\jdk1.6.0_24
    

    But if you ran the application using an specific jre:

    "C:\Program Files (x86)\Java\jre1.8.0_73\bin\java" -jar TheJavaFile.jar
    

    Inside the application on run-time, you will get on java.home a different version of the JAVA_HOME

    This may explain why on some cases you get different versions for both variable and system property.

    Also, please notice that the paths may be quite different, since JRE is a different product than JDK, then they are installed in different locations, because they are independent

    Now, regarding what's the difference from one JDK vs JRE, this diagram explains it pretty clear:

    JDK is a superset of JRE, and contains everything that is in JRE, plus tools such as the compilers and debuggers necessary for developing applets and applications. JRE provides the libraries, the Java Virtual Machine (JVM), and other components to run applets and applications written in the Java programming language.

提交回复
热议问题