Opening newly created jar file - "Failed to load Main-Class manifest attribute"
I'm trying to make a jar file but it never seems to work.
I have three class files, one with the main method, in the folder "hexMaze." In command prompt, I go to this directory, then type in "jar cvf HexMaze.jar *":
This makes the file HexMaze appear in my hexMaze folder. However, when I double-click it I get this error message:
C:\Documents and Settings\Aaron MacDonald\Desktop\hexMaze>jar cvf HexMaze.jar *
adding: HexArray.class(in = 3460) (out= 2057)(deflated 40%)
adding: HexCell.class(in = 2780) (out= 1390)(deflated 50%)
adding: HexDisplay.class(in = 1538) (out= 940)(deflated 38%)
C:\Documents and Settings\Aaron MacDonald\Desktop\hexMaze>
I also get this error message when I try to make my jar inside Eclipse. Can anyone tell me what's going on?
Failed to load Main-Class manifest attribute from C:\Documents and Settings\Aaron MacDonald\Desktop\hexMaze\HexMaze.jar
If it helps, I'm using jdk 1.5.03 on Windows XP. I believe my PATH variable is right, since I'm able to compile through the command promt (though when I try to run a file in the promt I get a bunch of NoClassDefFoundErrors...).
Easy steps to create an executable jar file: -
Just follow these 4 steps: -
1. Create a file ( for eg. call it Manifest.text )
Specify your main class ( the class having public static void main(String  args) method ) in the following format: -
2. Hit enter in the same file ( the last line should be blank but it should be there, JVM ignores the last line )
3. Now, create your jar file, using the following command: -
jar cfm <jarName>.jar <Manifest.text> <contents>
4. Your are ready to double click the jar file!
For example: -
Your main file is HexDisplay.java,
create a file named Mainfest.text and write here
with a new line after it.
Now, to make the jar file: -
Go the same directory where the contents are stored and execute
jar cfm HexMaze.jar Manifext.text .
the options cfm here tells -
c - create a jar file
f - put the output in the specified jar file
m - merge the contents of the default manifest file and the contents of the file specified.
It's done, run the jar file and your main class will get executed! :WAVE: