Java can run jar from cmd, but not double click

I just created a jar file using jdk7. I tried to run it, but kept getting an error message. It turned out that this was pointing to jre6, not 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, but he pulled out a window asking me to select a program to open it. When I selected the same javaw.exe file as above, it starts, but exits immediately, doing nothing. I can run it in cmd by running java -jar file.jar command. I even tried to remove the .jar registry key, but that only returned me to the moment when he asked me to choose a program to open. I use Windows 7 if that matters.

EDIT: There are 3 subkeys in the registry: OpenWithList, OpenWithProgids and UserChoice. I changed all the defaults to the path above, except for UserChoice, which will not allow me to edit it from regedit. When I delete this and try to run the jar file, it will open a program that opens again with a window. For some reason, it ignores other registry keys.

+6
source share
6 answers

I don’t know exactly why none of the solutions worked, but I reinstalled jre7 and now it works.

0
source

Ok, I found the answer somewhere else, but ran into this problem again, so I came here via google.
Decision...

  • Open regedit.exe
  • Search for " jre6 " or follow this example:
    HKLM->SOFTWARE->Classes->jarfile->shell->open->command
  • Change the data field to the directory of the javaw.exe file, which is located in your JDK directory.
  • For the love of God, remember to insert the strange parts [-jar "%1" %*] at the end.
  • Enjoy outsmarting Oracle.

Hope this saves some people a little.

This happened to me when I installed the jre6 plugin for Chrome, although it can happen when installing any other JRE , I think.

+11
source

I fixed this by going to regedit and looking for a jre that has grown ...

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

I changed 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"% *

+4
source

When windows ask you for a program to run, it will not insert the necessary -jar argument on the command line.

If it asks exe to run it, it means your JRE not associated with the .jar extension. You will need to modify the registry entry of the .jar file so that it works c:\path_to_jre\bin\javaw -jar %1 for it to work.
It used to be under File Explorer > Tools > Folder Options > File Types .

Then look for .jar. You should find a text box that shows the executable to run and command line arguments. This is what you want to change. You can also do this in the registry editor, but I forgot the path of the HKEY variable. I am sure this KBA will help:

support_microsoft_kb_950505

+2
source

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

 assoc .jar 

It seems that .jar is not related to jarfile.

+1
source

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

0
source

Source: https://habr.com/ru/post/896741/


All Articles