在netbeans中执行构建的jar文件时出现问题
我刚刚用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要使 JAR 能够自动执行,您必须在清单中包含
Main-Class
行。我不是 NetBeans 用户,但它就是这样做的。
创建一个
manifest.mf
文件:构建 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: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
Main-Class 属性后面需要换行才能正确解析。
显示您的
manifest.mf
,The Main-Class attribute needs a new line after it in order to be parsed correctly.
Show your
manifest.mf
,按照其他人的建议编辑清单文件,或者在 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.