0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Ahh, now that makes absolute sense. thank you :) Is there any way to access this windows registry to circumvent the need of adding the java installation to the PATH environment variable?
@Alrick, any solution involving the registry will only be far harder and time consuming for you. The command line is not designed to search the registry when executing programs so you would need to do it explicitly. You can manually query the registry to find out what executable gets used, but that just makes things more complicated for you. You can run assoc some_file.extension to get the program name associated with a given extension. Then you can run ftype "the program" to get the executable path formatting string that the file to open can be placed into and executed.
perfect! thank you very much for your expertise and your time

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.