Difference between java.home and JAVA_HOME

前端 未结 2 1103
渐次进展
渐次进展 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:30

    According to Oracle documentation java.home is a system property that represents the installation directory of Java Runtime Environment. JAVA_HOME is an environment variable - not a system property. Please refer to this post to check what is the difference between system property and environment variable.

    You can also refer to this post to learn more about JAVA_HOME.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题