双击执行 .jar 文件
我一直使用 Eclipse 作为我的 Java IDE,今天我遇到了一个有趣的问题。我使用内置的 file>export>runnable jar 文件为我的程序之一创建一个 jar 文件。如果我从命令行/使用批处理文件启动它,它可以完美运行,但不能通过双击运行。我绝对确定 .jar 文件与 javaw 关联,但它仍然不起作用。这不是一个我绝对需要解决的大问题,但如果有人有任何想法,我很乐意听到他们。
更新:我尝试使用 Aram Kocharyan 的解决方案(请参阅下面的答案)。运气不好。似乎也只是这一个 .jar 文件。所有其他罐子都通过双击启动。重建罐子没有帮助。 :P
I've been using Eclipse as my Java IDE and today I ran into an interesting problem. I used the built in file>export>runnable jar file to create a jar file for one of my programs. It runs perfectly if I start it from the command line/with a batch file, but doesn't run from a double click. I made absolutely certain that .jar files are associated with javaw and it still didn't work. It isn't a huge problem I absolutely NEED fixed, but if anyone has any ideas I'd love to hear them.
Update: I tried using Aram Kocharyan's solution (see answer below). No luck. It seems to be just this one .jar file too. All other jars launch with a double click. Rebuilding the jar doesn't help. :P
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不久前写了一篇关于此的简短指南,您可能会发现有帮助:
http://ak.net84.net/projects/how-to-make-a-multi-platform-executable-java-jar-file/
这将在双单击窗口而不进行任何其他设置,并且我已经在 Mac 上使用 Jar Launcher 对其进行了测试,并且没有出现任何问题。
I wrote a short guide on this a while back you might find helpful:
http://ak.net84.net/projects/how-to-make-a-multi-platform-executable-java-jar-file/
This will work on double click in windows without setting any additional settings, and I've tested it with the Jar Launcher on Mac and it doesn't complain.
使用..
javaw
打开你的jar
它位于 jre 的 bin 文件夹中...在我的电脑中它是 @
open your jar with..
javaw
which is in bin folder of jre... in my computer it is @
将其放入 .bat 中:
运行不需要选项
-Djava.library.path="native"
,我包含此选项是因为使用 .bat 的一个原因是双击.jar 是使用 JVM 参数,在我的例子中,我需要这个参数来运行我的项目。%~dp0 部分获取当前目录
Put this inside a .bat:
the option
-Djava.library.path="native"
its not required for run, i include this because one reason for using a .bat instead do a double click on a .jar is to use JVM-parameters, in my case i need this parameter for my project run.the %~dp0 part get current directory