可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Running a .jar file in a command line works fine, but i am not able to run any .jar file by double clicking on my Windows 7 (64). It seems nothing happens after the double click.
I tried the \"ftype\" hint, no success.
ftype jarfile=\"C:\\Program Files\\Java\\jre7\\bin\\javaw.exe\" -jar \"%1\" %*
I reinstalled the JDK 7 64-bit, no success.
Any idea?
回答1:
What is listed in right-click-> Open With ?
Is some other program listed as the default program ? Is a Java Runtime listed ? If a Java Runtime is listed, you can open with it, and make it the default program to run with.
ie,
Right Click -> Properties -> Change -> C:\\Program Files\\Java\\jre7\\bin\\javaw.exe
回答2:
If you have previously used the right click and opened with \\path\\to\\your\\javaw.exe then you will need to remove the following registry key.
[-HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.jar]
Then run
C:\\>assoc .jar=jarfile
C:\\>ftype jarfile=\"C:\\path\\to\\your\\javaw.exe\" -jar \"%1\" %*
回答3:
You may also run it from the Command Prompt (cmd):
java.exe -jar file.jar
回答4:
For Windows 7:
- Start \"Control Panel\"
- Click \"Default Programs\"
- Click \"Associate a file type or protocol with a specific program\"
- Double click
.jar
- Browse
C:\\Program Files\\Java\\jre7\\bin\\javaw.exe
- Click the button Open
- Click the button OK
回答5:
If you try unpopular\'s answer:
For Windows 7:
- Start \"Control Panel\"
- Click \"Default Programs\"
- Click \"Associate a file type or protocol with a specific program\"
- Double click
.jar
- Browse
C:\\Program Files\\Java\\jre7\\bin\\javaw.exe
- Click the button Open
- Click the button OK
And jar files still fail to open (in my case it was like I never double clicked):
open the Command Prompt (to be safe with admin rights enabled) and type the following commands:
java -version
This should return a version so you can safely assume java is installed.
Then run
java -jar \"PATHTOFILE\\FILENAME.JAR\"
Read through the output generated. You may discover an error message.
回答6:
I had the same problem with .jar files not opening on a double click. It turned out that I had two versions of Java installed (Java 6 and 7). Uninstalling Java 6 from Control Panel-> Uninstall a Program was what finally allowed .jar files to open on a double click without using the command window.
回答7:
I had the problem that windows was blocking it from running (Windows 10 Pro). Right click icon> properties> in the bottom right corner it might tell you \"Windows has blocked the functionality........\" next to it there is a check box labeled \"Unblock\"> uncheck the box> apply> option to block goes away and then you can run it.
回答8:
change the default application for JAR files from java.exe to javaw.exe from your JAVA_HOME/bin folder.
This is because, java.exe is console application only, but JAR file needs a window rendered execution. Since javaw.exe is a window application, it is preferred for the execution of JAR files.
An alternative to this is that to some extent you can use command prompt to run your JAR files by simply using java keyword with -jar attrib.
回答9:
This is my way:
Create file bat (example openJar.bat).
@echo off
start javaw -jar \"%1\" %*
exit
Cut it and paste to C:\\Program Files\\Java\\\\bin (this step is unnecessary, but you should it).
- Right click jar file > Properties > Choose open with (Change button ) and select your file bat.
- Double click your jar file to test it.
回答10:
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.
回答11:
check out this link
http://ostermiller.org/opening_jar_files.html
probably you haven\'t installed runtime or your system doesn\'t open .jar files with JAVA
回答12:
http://www.wikihow.com/Run-a-.Jar-Java-File
- Assuming you\'ve loaded the Java JRE and/or Java SDK, then
- To do associations, go to \"My Computer\", click on one of your drives (
C:
for instance).
- When it is shown, choose \"Tools\" »» \"Folder options\" (or Properties... it\'s in different places depending on the Windows version).
- Open Windows Explorer (just open any folder) to get the \"Tools\" -> \"Folder options\" window.
- When you get the \"Folder options\" window, click on the tab \"File types\". You should be able to either edit or add JAR files (
.jar
extension)
- Change the program used to open JAR files. In the file select window, go to the folder where the JRE is installed (should be
C:/Program Files/Java/...
, mark \"Always open with\", and select the javaw.exe
file.
回答13:
Installing the newest JRE fixed this for me.
(Even though I had a JDK and JRE(s) installed before.)
回答14:
Your problem might also be inside your Java code setting, I mean, if your program somehow could not realize the main class/main file (entry point), it will not launch the the program/.jar (specially application built on IDE\'s). To solve that on an IDE :
- Right Click the project > Properties > Run > Browse Main Class > OK.
- Clean and Rebuild
Try running it now. Hope it helps
回答15:
It\'s not a file association problem since you can launch the application correctly through command line.
The problem is when you double click on an associated file the application starts and runs with the file\'s path as base execution path. Any relative path will be computed from the file path and everything you try to load will probably be missing.
Nothing happens, even if you surround all of your entry point code with try/catch(Exception) because java s throwing Throwables and not Exceptions: to fix this in your java entry point surround the content of the main method with a try/catch(Throwable) (base class for Exception and Error) and debug.
回答16:
I created a project, JAR_Runnr, for precisely this. =)
http://projects.killerapplets.com/JAR_Runner/
回答17:
Had to try this:
- Open command prompt as admin
- Move to the file folder using
cd
command
- Type
java.exe -jar *filename*.jar
- Press enter
The app should pop right after that.