无法使用双击打开.jar,只能使用cmd [英] Can't open .jar using double-click, only with cmd

查看:160
本文介绍了无法使用双击打开.jar,只能使用cmd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Eclipse Indigo制作了一个非常简单的程序,并将其作为可执行jar导出到我的桌面。如果我使用命令java -jar SayHello.jar,该程序运行,但是如果我双击桌面上的SayHello.jar,我的鼠标将获得旋转的轮子,看起来好像在加载某些东西,没有发生任何事情。这是每个jar文件,而不只是这个。我已经搜索了几个小时如何解决这个问题,但没有任何工作。任何帮助将不胜感激。谢谢!

解决方案

对于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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆