Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java can run jar from cmd but not by double clicking

Tags:

java

windows

jar

I just created a jar file using jdk7. I tried running it but kept getting an error. It turned out it was pointing at a jre6 and not the jre in jdk7. So, I used the following command to change it

ftype jarfile = "C:\path to jre\bin\javaw.exe" -jar "%1" %*

After that, I tried to double click on my jar file again, but it popped up a window asking me to choose a program to open it with. When I chose the same javaw.exe file as above it runs but exits immediately without doing anything. I can run it fine in cmd by doing the java -jar file.jar command. I even tried deleting the .jar registry key, but that just got me back to the point where it asked me to choose a program to open with. I'm running windows 7 ultimate if that matters.

EDIT: In the registry there are 3 subkeys: OpenWithList, OpenWithProgids, and UserChoice. I've changed all the defaults to the path above except UserChoice which won't let me edit it from regedit. When I delete that and try to run the jar file, it opens up the choose a program to open with window again. For some reason it ignores the other registry keys

like image 863
jhlu87 Avatar asked Sep 06 '11 20:09

jhlu87


Video Answer


1 Answers

OK, I found the answer somewhere else but ran into this issue again so came here via google.
The solution is...

  1. Open up regedit.exe
  2. Either search for "jre6" or follow this:
    HKLM->SOFTWARE->Classes->jarfile->shell->open->command
  3. Change the Data field to the directory of the javaw.exe file that's in your JDK directory.
  4. For the love of God, don't forget to put the weird [-jar "%1" %*] parts on the end of it.
  5. Enjoy outsmarting Oracle.

Hopefully this'll save some people a bit of time.

This happened to me when I installed the JRE6 plugin for Chrome, though it could happen when installing any other JRE I guess.

like image 183
Dan Rayson Avatar answered Sep 22 '22 10:09

Dan Rayson