Home > Blockchain >  Why is the java PATH variable needed only for terminal execution?
Why is the java PATH variable needed only for terminal execution?

Time:01-13

Why is there no need to add the path of the java installation to the PATH variable when starting a jar with double-click while it is needed to start the jar from command line? Why does the OS only know where java is installed when executing with a double-click (without the PATH variable)?

Related Questions:

Is it necessary to set the path variable in java installation?

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

CodePudding user response:

When on the command line, you call an executable and pass it a file as an argument. Since it does not know where this executable is, you either need to call it with an absolute path (Includes the entire path from the drive letter to the executable) or the executable must be present in one of the locations listed in the system PATH environment variable.

However, when double clicking a file Windows does not have the luxury of being told which application it should use ahead of time. To solve this issue, Windows keeps a global registry of programs, file extensions, and various metadata about them. This includes stuff like which icon to display for that file type, the path to the executable used to open that file, extensions associated with a given program, the path to the uninstaller to use if deleted from the control panel, and much more.

The Java installer handles updating the registry for you behind the scenes so you don't need to, however depending on your installation setting it may not update the system path since most people will only use the double clicking method.

  •  Tags:  
  • Related