问题
When I double click the jar file, the GUI program doesn't start by itself. Instead I have to open the Command prompt and then type java -jar abc.jar
and only then it starts up. Why is that? What do I need to do to avoid this?
Is it that I have some problem with the default jar file opener? What should be the jar file opener?
回答1:
Maybe you would like to follow the instructions in this post: Running JAR file on Windows.
Just a minor note though. The exact syntax for me to work was in my Windows XP:
C:\Program Files\Java\j2re1.4.2_04\bin\javaw.exe -jar "%1" %
回答2:
Download the software from this link https://johann.loefflmann.net/downloads/jarfix.exe and run the software jarfix.exe. Upon clicking jarfix.exe it will pop up a window like this... click here to view the image
Hit ok... After that every GUI java jar file will start to run on double click instead of opening it using java -jar from the cmd
The problem gets solved like magic. Worked for me!!
回答3:
I had this same problem. In my case, I think it was because I was using Scanner(system.in) input.
By default, Windows opens .jar files with javaw.exe (thanks Johnydep), the version of java that runs without a terminal.
In my case, running javaw -jar myJar.jar
didn't work either.
I ended up writing a tiny batch file that uses the regular java.exe: java -jar myJar.jar
回答4:
Which operating system? You need to configure your default applications. In KDE this is under System Settings -> Default Applications. For Gnome, Mac, or Windows you will have to google to find where to set it.
回答5:
On windows: right click on jar -> open with -> choose programm... -> select "Java (TM) Platform SE binary".
Optionally, check the "Always use the selected programm to open this kind of file".
回答6:
if nothing happens, then don't you get any error message like could not find main class or something similar?
I would suggest check your jar file association. On command-line type:
ftype | find "jarfile"
Sometimes, even resetting it works, find out the absolute path of JRE and run the command:
ftype jarfile="C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*
This would most probably solve your problem.
回答7:
Navigate to:
File->export->Java->Jar file->Next->use the tree to select the files you want to be included in your jar->Next->Next->
now i guess comes the part you have missed
at the bottom under "Main Class" click "Browse"->selcet the class you want to run when double click->press ok->finish.
should work now.
I couldn't find this answer anywhere and it solved my problem after i had same issue.
回答8:
If your jar file opens successfully from the cmd line means its a correct jar and everything is in place. Now you have to associate the correct program with it.
Right click on the jar -> Open With -> Go to JRE/BIN/javaw.exe -> OK
Now all the jar files are associated with the correct program. Try now!
回答9:
I had the same problem in Linux with a jar generated by Intellij, and I find that it's the problem of permission, the jar file's permission is
"-rw-rw-r--", you need to add the permission of execute: $chmod +x xx.jar
, and double click.
回答10:
Maybe it is because your jar is not an executable jar due to which you cannot execute it directly by double clicking on it.
来源:https://stackoverflow.com/questions/9259389/jar-file-doesnt-open-upon-double-click