I had this same issue, and searched the internet for a solution and none of the suggestions didn’t not open by double clicking the .jar
file.
In my case the reason is I have multiple JDK & JRE versions installed on my computer. Since I am a software developer working with several different versions for different clients I need to use multiple JDKs in my PC (Windows 10 Pro). So I do not want to change the system variables (i.e. JAVA_HOME
, JRE_HOME
or PATH
), instead I use command prompt to run java in user process whenever I wanted to use a different version.
When installing JDK it registers the .jar
file association with latest version we installed in the PC. If you right click on the .jar icon and select properties, it will show that file opens with “Java(TM) Platform SE Binary”. If we look at the registry key: HKEY_CLASSES_ROOT\jarfile\shell\open\command
, it will point to latest JDK version.
It is not a good idea (sometimes annoying) to change the registry key every time I want to run an app build from a different version.
So in my situation it is impossible to just double click the .jar
file to execute it. But instead I found a work around solution myself.
Scenario:
Multiple JDKs (1.7, 1.8, 9.0, 10.0, 11.0, and 12.0)are installed in the PC, so the latest installed was 12.0.
Problem
Want to double click an executable .jar
developed using JDK 1.8 and didn’t work
This is my work around solution:
- Create a shortcut for the
.jar
file that you want to open.
- Right click the shortcut icon and select properties -> Shortcut tab
Change the text in the target (for example "D:\Dev\JavaApp1.8.jar"
)
To
"C:\Program Files\Java\jdk1.8.0\bin\javaw.exe
" -jar
"D:\Dev\JavaApp1.8.jar
"
Then click ok Double click the shortcut.
It should now open the app.