2

我想将 .jar 文件分发给外行观众(所有 Windows 用户)。但是我不能自己运行 jar 文件,除非我从 cmd 使用"java -jar "C:\..\file.jar".

当我双击该文件时,没有任何反应(默认程序是 Java Platform SE Binary)。有人建议这个网站,但我无法在 Win8 中跟进。

所以我希望用户能够双击 jar 文件并直接启动它,而无需我告诉他们打开命令提示符并输入内容,或者给他们链接。

PS:它是一个非常简单的非 GUI 应用程序。谢谢你的时间。

4

2 回答 2

1

How did you create the jar file? Jar files have a manifest file inside to, amount others, indicate the location of your main method. Check that this is correct.

You should be able to run the app by double clicking it but it can only be a program with a GUI or a program without direct user interaction.

于 2013-04-13T09:41:08.907 回答
1

我认为你最好的选择是创建一个file.bat运行 jar 的脚本,其中包含以下简单的行:

java -jar file.jar

给用户两个文件file.jarfile.bat,他们可以双击file.bat运行它。

理论上,如果 jar 文件中有一个清单 ( META-INF/MANIFEST.MF),其中定义了主类,Main-Class:那么它应该可以通过双击运行。但是,您说该应用程序没有 GUI,在这种情况下它可以正常运行,但您将看不到它。

无论如何,该bat文件应该有所帮助,在最坏的情况下,用户可以运行它而不必担心打字java -jar ...等。

于 2013-04-13T10:38:57.413 回答