0

I searched and found the link: How to open/run .jar file (double-click not working)? But it did not solve the problem, so I solved it by editing the registry.

Because of my reputation I could not post my answer to the above post so I asked it here to answer it myself.

ach
  • 56
  • 2
  • So since this is not a question but like a post just to archive an answer, this post seems invalid. As well please provide an instruction for your solution then? – pikkuez Jan 20 '20 at 12:37
  • Actually, it does work, if you configured your system (environment variables) and your jar file correctly. – Stultuske Jan 20 '20 at 12:40
  • @Stultuske double-click should work without setting environment variables so the problem is not about them and it's about registry. – ach Jan 20 '20 at 12:45
  • @ach if you believe that, it's no wonder it doesn't work. If your environment doesn't know where your Java is installed, or if you haven't configured it correctly, it can't work. remember, you're not trying to run it from within a Java environment, but from the OS itself. If the OS isn't configured with your JAVA_HOME, that's a problem to fix – Stultuske Jan 20 '20 at 12:50
  • @Stultuske the result is that I am running jar files without setting any environment variables isn't that a clean solution? – ach Jan 20 '20 at 12:54
  • @ach not really, now you even make your jar file OS dependent, which I assume is not what you need. Normally, everyone who has Java installed (which should be about every machine) can have their environment settings modified, those who don't have Java installed, can't execute your code anyway. – Stultuske Jan 20 '20 at 12:56

1 Answers1

2

Do the following (It is assumed that Java was installed already):

1 - Win+R -> regedit -> search jarfile and find the key HKEY_CLASSES_ROOT\jarfile\shell\open\command

2 - For the 'command' key there should be a default REG_EXPAND_SZ value (If it is not then create it)

3 - Use the string "path\to\java\bin\javaw.exe" -jar "%1" %* for the above value

ach
  • 56
  • 2
  • As an alternative you could also edit your environment variables to contain the java home directory. – SteffenJacobs Jan 20 '20 at 12:47
  • why do you need that? a decent manifest file is all you need, assuming your Java is correctly installed in your environment settings – Stultuske Jan 20 '20 at 12:51
  • Searching is not necessary, can put this in address bar in Registry Editor: `Computer\HKEY_CLASSES_ROOT\jarfile\shell\open\command`. – blackr1234 Jul 13 '22 at 17:25