Unable to run .jar files by double-clicking them on Windows 7
Solution 1
I ran into someone who had the same problem you did today. And somehow, I managed to fix it, although I am not sure entirely what fixed it; I can only offer you the approximate series of steps I've taken.
Using regedit, I found that HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE registry entries weren't in agreement. HKLM had the typical .jar
->jarfile
setup, with jarfile
pointing to the right path. HKCU had a .jar
-> jar_auto_file
association which pointed to an old an invalid path.
Editing this path did not fix it. I also tried pointing it to jarfile
, which didn't help either. I fussed with assoc
and ftype
a bit to see if this might wake Windows up; I figured the anti-hijacking functionality somehow prevented Windows from listening to the updated path. Sadly, it didn't do much.
So eventually I just deleted the jar_auto_file
entry. This gave me partial happiness: Windows finally realized the entry in the Open With
menu was the one with a working path. (Selecting the correct path/file in the past would never stick around correctly.) Sadly doubleclicking was still broken. However, just making sure the 'Always open this type of file with this program' box was checked and opening it finally fixed the association well enough that doubleclicking actually worked again.
Solution 2
I had the issue as well. The solution is even more simple. Add the missing -jar
argument.
Go to HKEY_CLASSES_ROOT\jar_auto_file\shell\open\command and set the default value to:
"C:\Program Files\Java\[...]\java.exe" "-jar" "%1"
All was missing was "-jar"
option.
Enjoy!
Solution 3
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 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.
Solution 4
I tried all above steps to resolve the problem but nothing worked. I had installed both JDK and JRE.
In my case, one jar file was being opened by double click while other was not being opened. I examined those files and the probable reason was that which was being opened, was created using JAVA SE 6 and the one not being opened was created using JAVA SE 7. Although, the problematic jar file was being run via command prompt (java -jar myfile.jar).
I tried Right Click -> Properties -> Change to javaw.exe with both in JDK\bin directory and JRE\bin directory.
I was finally able to fix the problem by changing javaw.exe path (from JDK\bin to JRE\bin) in registry editor.
Go to HKEY_CLASSES_ROOT\jarfile\shell\open\command, the value was,
"C:\Program Files\Java\jdk-11.0.1\bin\javaw.exe" -jar "%1" %*
I changed it to,
"C:\Program Files\Java\jre1.8.0_191\bin\javaw.exe" -jar "%1" %*
and it worked. Now the jar file can be opened by double click.
Related videos on Youtube
bobasti
Updated on September 18, 2022Comments
-
bobasti over 1 year
Running a .jar file in the command line works fine, but I am unable to execute .jar files on my PC by double-clicking them. What is interesting, the same .jar files successfully execute on my laptop with a double-click.
I included
%JAVA_HOME\bin
andJDK_HOME\bin
in thePATH
variable.
I haveJAVA_HOME
set toC:\Program Files\Java\jre1.8.0_121
.
I haveJDK_HOME
set toC:\Program Files\Java\jdk1.8.0_121
.For some period of time, the Java(TM) Platform SE binary disappeared from the
Open with
list, and I could not add it until I changed theHKEY_CLASSES_ROOT\jar_auto_file\shell\open\command
key inregedit.exe
to the appropriate version:C:\Program Files\Java\jre1.8.0_121\bin\javaw.exe" "%1".
Here is a snapshot of Windows CMD withjava -version
entered on my PC:
I tried the following methods, with no success:- reinstalling both JRE and JDK,
- associating .jar files with
C:\Program Files\Java\jre1.8.0_121\bin\javaw.exe
, - using
assoc .jar=jarfile
andftype jarfile="C:\Program Files\Java\jre1.8.0_121\bin\javaw.exe" -jar "%1" %*
in command line, - creating a new system Environment Variable OPENDS_JAVA_ARGS and setting it to -jar.
Additional information:- I am using Windows 7 Professional 64-bit (Service Pack 1) with latest updates installed both on my PC and laptop.
- Running .jar files by double-clicking them used to work on my PC, but suddently stopped working some time ago. I did not modify anything related to Java.
- I have the newest version of both JRE and JDK (Java 8 version 121).
- Of the .jar files I am trying to run, some are GUI Swing applications
and some open the system console (if not already open) using
Runtime.getRuntime().exec(String[])
.
I have already tried fixing this problem with solutions on the following links (without success):- https://stackoverflow.com/questions/8511063/how-to-run-jar-file-by-double-click-on-windows-7-64
- https://stackoverflow.com/questions/19966394/how-to-open-run-jar-file-double-click-not-working
- https://stackoverflow.com/questions/18434292/i-can-run-jar-files-through-cmd-but-i-cannot-double-click-them
- https://stackoverflow.com/questions/1724892/cant-run-jar-files
Notes:- I do not want to open .jar files with WinRAR.
- I do not want to open .jar files by running
java -jar jarfile.jar
in cmd.exe. - I am not looking for a 3rd party application to run .jar files.
For now, I am usingC:\Windows\System32\cmd.exe /k "java -jar C:\path\to\jarfile\Program.jar"
as a shortcut location to run jar files, but I am not satisfied with this solution as this opens the console to run even Swing applications.I asked the same question over on stackoverflow, but it was pointed out to me that superuser is more suitable for this kind of question.
-
bobasti almost 7 yearsI managed to get Java(TM) Platform SE binary in the Open with list by matching paths in
HKEY_CURRENT_USER
andHKEY_LOCAL_MACHINE
registry entries. Now.jar
files are finally showing icons, but still do not work on double click. -
bobasti almost 7 yearsUPDATE: I deleted
.jar
andjar_auto_file
entries fromHKEY_CURRENT_USER/Software/Classes
and it worked! .jar files are opening on double-click again! -
klonq over 4 yearsThe shortcut solution is the only one which worked for me.
-
White_King almost 4 yearsThank you so much!! This a hard topic to find. but clearly you meant: .jar_auto_file instead of jar_auto_file on the registry path leaving: HKEY_CLASSES_ROOT\.jar_auto_file\shell\open\command. I wasn't able to find it until I saw it.