What is the point of setting JAVA_HOME environmental variable when the only thing you have to set is the Path variable to call java from the command line, which is the primary purpose, right ?
Asked
Active
Viewed 603 times
2
-
There wouldn't be much point if that was all it was used for. Other programs use it, though the `java` on the path is usually enough. – Peter Lawrey Feb 01 '16 at 13:41
-
@PeterLawrey What are other uses for those paths and variables other than to be able to invoke an executable through command line from any directory ? – Shady Programmer Feb 01 '16 at 17:40
-
Some programs use JAVA_HOME is their startup script e.g. IntelliJ does. – Peter Lawrey Feb 02 '16 at 01:21
3 Answers
3
JAVA_HOME is just a convention, usually used by Java EE app servers like Tomcat and build tools such as Gradle to find where Java lives.
You could also use JAVA_HOME to set the PATH variable, something like this..
%JAVA_HOME%\bin;
So that you dont have to meddle with PATH variable every time, if you have to switch between two JDKs or two JREs of different versions

codeMan
- 5,730
- 3
- 27
- 51
2
Some application takes JAVA_HOME to execute/configure themselves instead of using the java executable in the PATH: tomcat, maven, weblogic, eclipse, etc...
So it's a good idea to have this variable properly set.

jfcorugedo
- 9,793
- 8
- 39
- 47
-
but that's what my question is about: if those applications can see java in the PATH what's the point ? If JAVA_HOME and PATH are pointing to the same executable? – Shady Programmer Feb 01 '16 at 13:52
-
1@ShadyProgrammer What if they don't? I believe I have at least two Java installations on my laptop, what if I want to switch which one is used without messing with $PATH? – Dan Lowe Feb 01 '16 at 13:56
-
-
1That's. If you have some Java versions, JAVA_HOME is an easy way to switch from one to another. – jfcorugedo Feb 01 '16 at 14:01
1
IMO this is a unix thing where the OS's files are saved. Windows is totally different. But since Java is installed into Program files in Windows it doesn't make sense either.

Micromega
- 12,486
- 7
- 35
- 72