First: I realize that this issue should be quite simple and lots of people seem to have experienced it. However, it appears my issue may be slightly different from
search your regedit and check follow item
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Applications\javaw.exe\shell\open\command]
@="\"C:\\Program Files (x86)\\Java\\jre6\\bin\\javaw.exe\" -jar \"%1\""
[HKEY_CLASSES_ROOT\jarfile\shell\open\command]
@="\"C:\\Program Files (x86)\\Java\\jre6\\bin\\javaw.exe\" -jar \"%1\""
[HKEY_CURRENT_USER\Software\Classes\Applications\javaw.exe\shell\open\command]
@="\"C:\\Program Files (x86)\\Java\\jre6\\bin\\javaw.exe\" -jar \"%1\""
If the methods above cannot solve the problem, try deleting the .jar file type from your pc (you can google a software called Unassoc.exe and delete the file type), and then the problem is fixed! (At least, this is my case!)
I came across this error as well. I checked the file association using command prompt and all was correct. It wasn't until I tried running the .jar from the command line using java -jar MyProgram.jar
that it actually showed me the root of the problem.
It turns out the .jar was compiled under JDK 7 whereas I was only running JRE 6. This was error given to me in the prompt which lead me to the real solution:
Exception in thread "main" java.lang.UnsupportedClassVersionError: MyProgram/Program : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: MyProgram.Program. Program will ex
it.
Perhaps your file associations got messed up. At the command prompt, try running
ftype | find "jarfile"
On my 64-bit Windows 7 computer, that shows
jarfile="C:\Program Files (x86)\Java\jre6\bin\javaw.exe" -jar "%1" %*
You can also change it with ftype
:
ftype jarfile="C:\Program Files (x86)\Java\jre6\bin\javaw.exe" -jar "%1" %*
Just found this post...
If you have the problem only when double clicking the jar file and not at cmd launch, it's probably because the version of the JRE is wrong (6 in place of 7).
Just change the value in regedit at :
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\jarfile\shell\open\command]
"C:\Program Files (x86)\Java\jre6\bin\javaw.exe" -jar "%1" %*
to :
"C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*
There should be no problem if this value is updated.
Note : Switching between 32 and 64 bits versions on Windows :
-> "C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*
will use the 64 bits version of the JRE
-> "C:\Program Files (x86)\Java\jre7\bin\javaw.exe" -jar "%1" %*
will use the 32 bits version of the JRE
I just had the exact same problem, fixed the same way. I had to completely delete the association, not just the user customisation, and reinstall the JRE.
The association before the fix was still:
jarfile="C:\Program Files (x86)\Java\jre6\bin\javaw.exe" -jar "%1" %*
And after (the same):
jarfile="C:\Program Files (x86)\Java\jre6\bin\javaw.exe" -jar "%1" %*