8

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

ring bearer
  • 20,383
  • 7
  • 59
  • 72
jhlu87
  • 3,999
  • 8
  • 38
  • 48

6 Answers6

15

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.

Chandra Sekhar
  • 16,256
  • 10
  • 67
  • 90
Dan Rayson
  • 1,315
  • 1
  • 14
  • 37
  • The correct key for me (Win7) was HKEY_CURRENT_USER\Software\Classes\jar_auto_file\shell\open\command as the "global" association was lost altogether and I had tried to open the jar with "OpenWith" – Jouni Aro Mar 12 '14 at 09:07
4

I fixed it by going to regedit and searched for jre which brought up...

HKEY_CURRENT_USER/Software/Classes/Applications/javaw.exe/shell/open/command

I changed the REG_SZ

from: "C:\Program Files (x86)\Java\jre7\bin\javaw.exe" "%1"

to: "C:\Program Files (x86)\Java\jre7\bin\javaw.exe" -jar "%1" %*

daver70
  • 41
  • 2
2

When windows asks you for a program to run it against it won't insert the needed -jar argument in the command line.

If it's asking you for the exe in which to run it then that means somehow your JRE isn't associated with the .jar extension. You'll need to modify the .jar file registry entry so that it runs c:\path_to_jre\bin\javaw -jar %1 in order for it to work.
It used to be under File Explorer > Tools > Folder Options > File Types.

Then look for .jar in there. You should find a text field that shows the executable to run and the command line arguments. That's what you want to modify. You can also do it in the registry editor too, but I've forgotten the HKEY variable path. I'm sure this KBA will help:

support_microsoft_kb_950505

Chandra Sekhar
  • 16,256
  • 10
  • 67
  • 90
chubbsondubs
  • 37,646
  • 24
  • 106
  • 138
  • 1
    That association is exactly what the `ftype` command shown by jhlu87 is doing. –  Sep 06 '11 at 20:34
1

Check if the file type jarfile is actually registered with the *.jar extension using

assoc .jar

Seems like .jar is not linked to jarfile.

1

I'm not sure exactly why none of the solutions worked, but I reinstalled jre7 and it works now.

jhlu87
  • 3,999
  • 8
  • 38
  • 48
0

Isn't it easier to change your java version to you rnew jdk7 by changing the CLASSPATH environment variable? See how here

tb189
  • 1,942
  • 3
  • 22
  • 37