user2044296
user2044296

Reputation: 524

Is JAVA_HOME variable needed when Java Path is defined in system environment variable?

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?

Upvotes: 6

Views: 3606

Answers (1)

QBrute
QBrute

Reputation: 4541

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.

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.

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.

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.

Upvotes: 8

Related Questions