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:
reinstalling both JRE and JDK,
associating .jar files with C:\Program Files\Java\jre1.8.0_121\bin\javaw.exe,
using assoc .jar=jarfile and ftype 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):
How to run .jar file by double click on Windows 7 (64)
How to open/run .jar file (double-click not working)?
I can run .jar files through cmd, but I cannot double click them
Can't 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 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.
UPDATE: SOLUTION
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.
Related
I just installed Oracle JDK 11 on my Windows 10. I noticed that the PATH variable doesn't include the JDK 11 path. Also the .JAR file extension is not associated with javaw. Our users used to doubleclick JAR file to execute the client Java/SWING application. With Java 11 this doesn't work. Is this a bug or feature? I know how to set the PATH and start the application manually using the command line. I just want to make it easier for end-users. Any ideas?
There is no Public JRE in Java 11, as there was in the previous Java versions. Don't be confused with the jre directory in previous JDK version, it's not a Public JRE. Also installers of the old Public JRE copied the java.exe and the javaw.exe programs into the C:\Windows\System32 directory that is defined in the PATH environment variable by default. They also did many other thing, like changes in your Windows registry. Installers of the old Public JRE had never changed anything in the PATH.
Official alternative to the Public JRE is a custom runtime environment that you can built by the jlink tool of the JDK. However in this case you will have no jar file at all but UNIX shell and Batch scripts.
If you don't like it you may use JDK 11 and associate the jar files in Windows Explorer with javaw.exe of JDK, instead of JRE, as described there Running JAR file on Windows
Open regedit.exe
Select HKEY_CLASSES_ROOT
Create new key .jar
Type jarfile to default value
img
In HKEY_CLASSES_ROOT create new key jarfile
In jarfile create key tree like
jarfile
DefaultIcon
shell
open
command
[Optional] Type path to icon/executable file to default value in DefaultIcon
Type path to javaw.exe to default value in command like "C:\Java\jdk11\bin\javaw.exe" -jar "%1"
img
Now select javaw.exe when opening the program.
I made a bat file, which contains the following:
java -jar %1
Click on a jar > open with > select your bat
If java path is set correctly (check with java -version) it will run your jar after double clicking.
I know this question has been beaten to death but I still cannot get the SDK Manager to run on my Windows 7 Home.
I downloaded the eclipse + adt bundle. The SDK Manager.exe is in the sdk folder where I try to run it from. I even tried copying it to the tools folder and tried running from there but no luck.
The error I get is:
Failed to execute tools\android.bat:
The system cannot find the file specified.
The file clearly exists. I tried running it as "Administrator" as well.
Next I tried running the android.bat file itself which says:
Windows cannot find 'E:\path\to\batfile'.
Make sure you typed the name correctly, and then try again.
I then ran it as "Administrator" which at least detects and tries to execute it. I added in a few pause statements to android.bat itself to prevent it from closing.
Here is what I see:
'"E:\ADT\sdk\tools\lib\\find_java.exe" -s' is not recognized as an internal
or external command, operable program or batch file.
ERROR: No suitable Java found. In order to properly use the Android Developer
Tools, you need a suitable version of Java JDK installed on your system.
We recommend that you install the JDK version of JavaSE, available here:
http://www.oracle.com/technetwork/java/javase/downloads
If you already have Java installed, you can define the JAVA_HOME environment
variable in Control Panel / System / Avanced System Settings to point to the
JDK folder.
Not sure why it says that because when I run where java in cmd I get this:
C:\Users\(MyUser)>where java
C:\Program Files\Java\jdk1.8.0_05\bin\java.exe
C:\ProgramData\Oracle\Java\javapath\java.exe
C:\Windows\System32\java.exe
And when I open cmd and manually run
'"E:\ADT\sdk\tools\lib\\find_java.exe" -s'
it works fine.
I then tried setting the java_exe in android.bat to
set java_exe=C:\Program Files\Java\jdk1.8.0_05\bin\java.exe
After commenting out the find_java I ran it again and this is what I get:
'"C:\Program Files\Java\jdk1.8.0_05\bin\java.exe" -jar lib\archquery.jar' is not
recognized as an internal or external command,
operable program or batch file.
Invalid path
And once again, when I manually run it, I get:
C:\Users\MyUser>"C:\Program Files\Java\jdk1.8.0_05\bin\java.exe" -jar E:\ADT\sdk\t
ools\lib\archquery.jar
x86_64
Am I missing something or should I finally give up trying to get it to work on my windows machine.
Your where java shows too many java.exe, the find_java.bat will try to look for javaw as well in the folder where java is.
set JAVA_HOME and make sure the echo %PATH% points to your main jdk installation.
I have CQ5 executable jar file.It is suppose to be executed on double clicking.But i get error saying "could not find Main class program will exit".The same jar file executed on all my team mates machine but i am unable to execute it.
I am working on windows 7 OS.
I have jre6 installed.
I have done all steps provided in following link .jar file keeps giving me " could not find the main class". Program will exit.
my ftype and assoc is set to propervalue.
there is no problem in manifest file(becoz it executed on others machine).
all my path variables are set properly.
type of file on my system is "JAR" but on everyone else machine its "Executable JAR"
Could not figure out what is problem with my system.
Help plz.
You can alternatively try executing this command from a command console,
first CD to the location where you have the jar file and execute
For Win7 32-bit:
java -Xmx1024M -jar .jar
For Win7 64-bit:
java -XX:MaxPermSize=256m -Xmx1024M -jar .jar
if you have supported version of Java installed correctly, then the command should be able to start the CQ5 server. In that case, for fixing the double click issue, you would need to fix the filetype association of .jar files to open with /bin/javaw.exe
For supported Java versions, refer
CQ5.5 http://dev.day.com/docs/en/cq/5-5/deploying/technical_requirements.html
CQ5.6 http://dev.day.com/docs/en/cq/5-6/deploying/technical_requirements.html
I have the next problem - my .jar file works when I invoke it from the command line as java -jar name.jar
But it does not start when I double click on it on the desktop of my Windows 7...
Moreover, when I try to start it with clicking the right buttonof the mouse "open with" and choose Java(TM) SE platform binary it does not start either
How to make it start with the double click?
Apparently the .jar extension is not associated with javaw.exe on your computer.
To do this, run the following two commands in a commandline window:
ftype jarfile="C:\Program Files\Java\jre6\bin\javaw.exe" -jar "%1" %*
assoc .jar jarfile
(Adjust the path to javaw.exe to your installation path)
You should run this with an account that has administrative privileges as this will update the globel registry.
Edit (after the comments):
As Java7 is not yet that widespread, you should re-compile your sources using the compiler switch -target 1.6 or compile them using Java6 right from the start. The your jar file should also with Java6
I just created a jar file using jdk7. I tried running it but kept getting an error. It turned out it was pointing at a jre6 and not the jre in jdk7. So, I used the following command to change it
ftype jarfile = "C:\path to jre\bin\javaw.exe" -jar "%1" %*
After that, I tried to double click on my jar file again, but it popped up a window asking me to choose a program to open it with. When I chose the same javaw.exe file as above it runs but exits immediately without doing anything. I can run it fine in cmd by doing the java -jar file.jar command. I even tried deleting the .jar registry key, but that just got me back to the point where it asked me to choose a program to open with. I'm running windows 7 ultimate if that matters.
EDIT:
In the registry there are 3 subkeys: OpenWithList, OpenWithProgids, and UserChoice. I've changed all the defaults to the path above except UserChoice which won't let me edit it from regedit. When I delete that and try to run the jar file, it opens up the choose a program to open with window again. For some reason it ignores the other registry keys
OK, I found the answer somewhere else but ran into this issue again so came here via google.
The solution is...
Open up regedit.exe
Either search for "jre6" or follow this: HKLM->SOFTWARE->Classes->jarfile->shell->open->command
Change the Data field to the directory of the javaw.exe file that's in your JDK directory.
For the love of God, don't forget to put the weird [-jar "%1" %*] parts on the end of it.
Enjoy outsmarting Oracle.
Hopefully this'll save some people a bit of time.
This happened to me when I installed the JRE6 plugin for Chrome, though it could happen when installing any other JRE I guess.
I fixed it by going to regedit and searched for jre which brought up...
HKEY_CURRENT_USER/Software/Classes/Applications/javaw.exe/shell/open/command
I changed the REG_SZ
from: "C:\Program Files (x86)\Java\jre7\bin\javaw.exe" "%1"
to: "C:\Program Files (x86)\Java\jre7\bin\javaw.exe" -jar "%1" %*
When windows asks you for a program to run it against it won't insert the needed -jar argument in the command line.
If it's asking you for the exe in which to run it then that means somehow your JRE isn't associated with the .jar extension. You'll need to modify the .jar file registry entry so that it runs c:\path_to_jre\bin\javaw -jar %1 in order for it to work.
It used to be under File Explorer > Tools > Folder Options > File Types.
Then look for .jar in there. You should find a text field that shows the executable to run and the command line arguments. That's what you want to modify. You can also do it in the registry editor too, but I've forgotten the HKEY variable path. I'm sure this KBA will help:
support_microsoft_kb_950505
Check if the file type jarfile is actually registered with the *.jar extension using
assoc .jar
Seems like .jar is not linked to jarfile.
I'm not sure exactly why none of the solutions worked, but I reinstalled jre7 and it works now.
Isn't it easier to change your java version to you rnew jdk7 by changing the CLASSPATH environment variable? See how here