Problem in executing a built jar file in netbeans
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 a开发者_StackOverflownd getting the exception: Failed to load Main-Class manifest attribute from Game.jar
What to do???
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
The Main-Class attribute needs a new line after it in order to be parsed correctly.
Show your manifest.mf
,
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.
精彩评论