无法使用双击打开.jar,只能使用cmd [英] Can't open .jar using double-click, only with cmd
问题描述
对于Java Windows (您没有实际指定)当您发现,双击 .jar
文件时,将使用 javaw
JVM运行它,即GUI模式,代码写入 System.out
的任何东西都被丢弃。 java
JVM将输出到控制台窗口,但如果通过双击创建该窗口,则会在代码退出时立即消失。请注意 .jar
的关联(在 HKCR\jarfile\必须
(YOUR_JREDIR_usually_progfiles-arch-jre-version )\bin\javaw.exe-jar%1%*
或 java.exe
用于控制台,在任何一种情况下,与 -jar
。我不相信控制面板会正确设置这样的额外的标志参数,这将导致找不到主类。
具有两个行 java -jar myjar
然后 pause
当doubleclicked应该运行该类,当它退出等到你按任何键,然后再摧毁窗户。您可以使用 timeout numseconds
限制等待。
ADDED:双击JAR文件不打开命令提示符有另一种方式来保持控制台窗口不会消失:使用 cmd / s / k
而不是批处理文件。
I made a very simple program with Eclipse Indigo and exported it as an executable jar to my desktop. If I use the command "java -jar SayHello.jar", the program runs, but if I double click SayHello.jar on my desktop, my mouse gets the spinning wheel, looking as if it is loading something, but then the wheel goes away and nothing ever happens. This happens for every jar file, not just this one. I have searched for hours on how to fix this, but nothing has worked. Any help would be greatly appreciated. Thanks!
For Java on Windows (which you didn't actually specify) the default action when doubleclicking a .jar
file, as you found, is to run it with the javaw
JVM which is "GUI" mode and anything the code writes to System.out
is discarded. The java
JVM does output to the console window, but if that window was created by double-clicking it vanishes as soon as the code exits, as you found.
Note the "association" for .jar
(in HKCR\jarfile\shell\open\command
) must be
"(YOUR_JREDIR_usually_progfiles-arch-jre-version)\bin\javaw.exe" -jar "%1" %*
or java.exe
for console, in either case with the -jar
. I don't believe control panel will set extra flag arguments like that correctly, and that would account for the "cannot find main class".
A batch file with two lines java -jar myjar
and then pause
when doubleclicked should run the class and when it exits wait until you press any key before destroying the window. You can instead use timeout numseconds
to limit the wait.
ADDED: Double Clicking JAR file does not open Command Prompt has another way to keep the console window from disappearing: use cmd /s /k
instead of a batch file.
这篇关于无法使用双击打开.jar,只能使用cmd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!