views:

131

answers:

3

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???

+1  A: 

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

Show your manifest.mf,

Paul Creasey
+4  A: 

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

Matt
Good explanation! I'd just like to emphasize that 'YourGame' is the fully qualified classname, iaw most likely `my.pckg.containing.YourGame` or so. And if the game depends on other libraries, you can not use the `-cp` parameter in conjunction with `-jar` - it's almost always better to start the app with Matt's second suggestion.
Andreas_D
+1  A: 

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.

Messa