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
and JDK_HOME\bin
in the PATH
variable.
I have JAVA_HOME
set to C:\Program Files\Java\jre1.8.0_121
.
I have JDK_HOME
set to C:\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 the HKEY_CLASSES_ROOT\jar_auto_file\shell\open\command
key in regedit.exe
to the appropriate version:
C:\Program Files\Java\jre1.8.0_121\bin\javaw.exe" "%1".
Here is a snapshot of Windows CMD with java -version
entered on my PC:
I tried the following methods, with no success:
C:\Program Files\Java\jre1.8.0_121\bin\javaw.exe
,assoc .jar=jarfile
and ftype jarfile="C:\Program Files\Java\jre1.8.0_121\bin\javaw.exe" -jar "%1" %*
in command line,
Additional information:
Runtime.getRuntime().exec(String[])
.
I have already tried fixing this problem with solutions on the following links (without success):
Notes:
java -jar jarfile.jar
in cmd.exe.
For now, I am using C:\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 managed to get Java(TM) Platform SE binary (javaw.exe)
in the Open with list by matching paths in HKEY_CURRENT_USER
and HKEY_LOCAL_MACHINE
registry entries:
HKEY_CURRENT_USER\Software\Classes\jar_auto_file\shell\open\command
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\jarfile\shell\open\command
Seems like one of the entries pointed to an older version of Java. Now .jar
files are finally showing icons, but still do not work on double-click.
Delete the .jar
and jar_auto_file
entries from HKEY_CURRENT_USER/Software/Classes
and it should work. .jar
files should open on double-click again.
Make sure to backup these entries first by right-clicking the entry and choosing Export
.
Additional information can be found on superuser.