在netbeans中执行构建的jar文件时出现问题

发布于 2024-08-18 10:51:43 字数 108 浏览 2 评论 0原文

我刚刚用netbeans 做了一个游戏。问题是在构建游戏之后。我无法执行 jar 文件并收到异常: 无法加载主类清单属性 Game.jar

做什么???

I've just made a game in netbeans. The Problem is that after builting the game. I'm not able to execute the jar file and getting the exception:
Failed to load Main-Class manifest attribute from
Game.jar

What to do???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

娇女薄笑 2024-08-25 10:51:43

要使 JAR 能够自动执行,您必须在清单中包含 Main-Class 行。

我不是 NetBeans 用户,但它就是这样做的。

创建一个 manifest.mf 文件:

Main-Class: YourGame
<newline>

构建 jar:
jar cmf manifest.mf Game.jar path/to/classes/*.class

您现在应该能够双击 JAR 来运行它(假设是 Windows),或者您也可以运行它通过命令行:

java -jar Game.jar

当然,您始终可以从命令行运行,无需清单:

java -cp .;Game.jar YourGame

For a JAR to be self-executable, you have to include the Main-Class line in a manifest.

I'm not a NetBeans user, but this is how it's done.

Create a manifest.mf file:

Main-Class: YourGame
<newline>

Build the jar:
jar cmf manifest.mf Game.jar path/to/classes/*.class

You should now be able to to double-click on the JAR to run it (assuming Windows), or you can run it via the command line:

java -jar Game.jar

Of course, you can always run from the command line without the need for a manifest:

java -cp .;Game.jar YourGame

谁的新欢旧爱 2024-08-25 10:51:43

Main-Class 属性后面需要换行才能正确解析。

显示您的 manifest.mf

The Main-Class attribute needs a new line after it in order to be parsed correctly.

Show your manifest.mf,

一片旧的回忆 2024-08-25 10:51:43

按照其他人的建议编辑清单文件,或者在 NetBeans 中只需右键单击项目(在侧栏中),选择“属性”、类别“运行”并点击“浏览...” 在主类旁边。

Edit manifest file as proposed by others, or in NetBeans just right-click the project (in sidebar), select Properties, category Run and hit Browse... next to Main Class.

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