双击执行 .jar 文件

发布于 2025-01-02 05:54:06 字数 312 浏览 3 评论 0原文

我一直使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鯉魚旗 2025-01-09 05:54:06

我不久前写了一篇关于此的简短指南,您可能会发现有帮助:

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.

隔岸观火 2025-01-09 05:54:06

使用..javaw
打开你的jar
它位于 jre 的 bin 文件夹中...在我的电脑中它是 @

C:\Program Files\Java\jre\bin\javaw.exe

open your jar with..javaw
which is in bin folder of jre... in my computer it is @

C:\Program Files\Java\jre\bin\javaw.exe
飘落散花 2025-01-09 05:54:06

将其放入 .bat 中:

start javaw -classpath "%~dp0YOU-JAR-NAME.jar" -Djava.library.path="native" foo.package.bar.YourClassWithMainMethod

运行不需要选项 -Djava.library.path="native" ,我包含此选项是因为使用 .bat 的一个原因是双击.jar 是使用 JVM 参数,在我的例子中,我需要这个参数来运行我的项目。

%~dp0 部分获取当前目录

Put this inside a .bat:

start javaw -classpath "%~dp0YOU-JAR-NAME.jar" -Djava.library.path="native" foo.package.bar.YourClassWithMainMethod

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文