java.home和JAVA_HOME之间的区别 [英] Difference between java.home and JAVA_HOME

查看:100
本文介绍了java.home和JAVA_HOME之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Java代码中,我有这行 System.getProperty("java.home").在某些环境中,它返回与 JAVA_HOME 作为环境变量设置的值相同的值.

但是在某些环境中, System.getProperty("java.home")返回的值与 JAVA_HOME 完全不同.

所以我的问题是,从Java角度来看, java.home JAVA_HOME 有什么区别?

从研究中我知道的是 JAVA_HOME 是jdk安装路径, java.home 是jre安装路径,但是为什么它不能匹配,因为jre可以jdk安装的一部分.

解决方案

如您所述, JAVA_HOME 指向环境变量(%JAVA_HOME%).

但是 java.home 指向

JDK是JRE的超集,并且包含JRE中的所有内容,以及开发所需的工具,例如编译器和调试器小程序和应用程序.JRE提供了Java Virtual库机器(JVM)和其他运行小程序和应用程序的组件用Java编程语言编写的.

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 as environment variable.

But in some environments, System.getProperty("java.home") returns completely different value from JAVA_HOME.

So my question is what's the difference between java.home and JAVA_HOME from java perspective?

What i know from my research is JAVA_HOME is jdk installation path, java.home is jre installation path, but then why can't it match as jre can be part of jdk installation.

解决方案

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.

这篇关于java.home和JAVA_HOME之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆