在系统环境变量中定义Java Path时,是否需要JAVA_HOME变量?

时间:2022-09-29 23:22:27

I've set JAVA path in path variable of system environment but not defined JAVA_HOME variable and still I'm able to execute my JAVA programs, why is it happening, is JAVA_HOME variable not needed when JAVA path is defined?

我已经在系统环境的路径变量中设置了JAVA路径,但没有定义JAVA_HOME变量,我仍然能够执行我的JAVA程序,为什么会发生这种情况,JAVA路径定义时不需要JAVA_HOME变量?

1 个解决方案

#1


2  

For Java itself there's no need for such a variable. All it cares about is that the path to its \bin folder is on the PATH. That is the case when you want to execute Java on your console with just calling java.

对于Java本身,不需要这样的变量。所有它关心的是它的\ bin文件夹的路径在PATH上。当您想要在控制台上执行Java而只调用java时就是这种情况。

Otherwise, as @CarlosHeuberger mentioned, you don't even need the path to your java executable in your PATH variable if you're calling it by its absolute path.

否则,正如@CarlosHeuberger所提到的,如果您通过其绝对路径调用它,则甚至不需要PATH变量中的java可执行文件的路径。

I think other systems depend on the existence of a variable called JAVA_HOME, for example Tomcat or Gradle so that they know where Java lies.

我认为其他系统依赖于一个名为JAVA_HOME的变量的存在,例如Tomcat或Gradle,以便他们知道Java所在的位置。

Although there is a benefit of having an explicit JAVA_HOME variable. After updating/upgrading your Java version, you only have to point that variable to the new installation folder without touching PATH.

虽然有一个明确的JAVA_HOME变量的好处。更新/升级Java版本后,您只需将该变量指向新安装文件夹而不触及PATH。

#1


2  

For Java itself there's no need for such a variable. All it cares about is that the path to its \bin folder is on the PATH. That is the case when you want to execute Java on your console with just calling java.

对于Java本身,不需要这样的变量。所有它关心的是它的\ bin文件夹的路径在PATH上。当您想要在控制台上执行Java而只调用java时就是这种情况。

Otherwise, as @CarlosHeuberger mentioned, you don't even need the path to your java executable in your PATH variable if you're calling it by its absolute path.

否则,正如@CarlosHeuberger所提到的,如果您通过其绝对路径调用它,则甚至不需要PATH变量中的java可执行文件的路径。

I think other systems depend on the existence of a variable called JAVA_HOME, for example Tomcat or Gradle so that they know where Java lies.

我认为其他系统依赖于一个名为JAVA_HOME的变量的存在,例如Tomcat或Gradle,以便他们知道Java所在的位置。

Although there is a benefit of having an explicit JAVA_HOME variable. After updating/upgrading your Java version, you only have to point that variable to the new installation folder without touching PATH.

虽然有一个明确的JAVA_HOME变量的好处。更新/升级Java版本后,您只需将该变量指向新安装文件夹而不触及PATH。