I can\'t open or run my .jar file.
I just installed java, but I tried to open the .jar with other programs first, so the double-click defaults to something else and
An easy way to execute .jar files is to create a batch file.
Let's say you placed your jar file on your Desktop;
@echo OFF
java -jar C:\Users\YourName\Desktop\myjar.jar
Copy this code to a .txt file, modify "YourName" and save as "myjar.bat". Then whenever you double click, the jar file will be executed. Hope this helps.
I was having this same issue for both Windows 8 and Windows Server 2012 configurations.
I had installed the latest version of JDK Java 7 and had set my **JAVA_HOME**
system env variable to the jre folder: *C:\Program Files (x86)\Java\jre7*
I also added the bin folder to my **Path**
system env variable: *%JAVA_HOME%\bin
*
But I was still having problems with double clicking the executable jar files. I found another system env variable OPENDS_JAVA_ARGS
that can be used to set the optional properties for javaw.exe. So I added this variable and set it to: -jar
Now I am able to run the executable jar files when double clicking them.
You may have several JDKs installed in your PC. Some older JDK installers also copy some java files such as java.exe
, javaw.exe
into C:\Windows\System32
folder.
I had a similar issue, and searched the internet for a solution and none of the suggestions didn’t 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.