Opening newly created jar file - "Failed to load Main-Class manifest attribute"


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 11 of 11

Thread: Opening newly created jar file - "Failed to load Main-Class manifest attribute"

  1. #1
    Join Date
    Apr 2005
    Posts
    18

    Question 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 *":
    C:\Documents and Settings\Aaron MacDonald\Desktop\hexMaze>jar cvf HexMaze.jar *
    added manifest
    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>
    This makes the file HexMaze appear in my hexMaze folder. However, when I double-click it I get this error message:
    Failed to load Main-Class manifest attribute from C:\Documents and Settings\Aaron MacDonald\Desktop\hexMaze\HexMaze.jar
    I also get this error message when I try to make my jar inside Eclipse. Can anyone tell me what's going on?

    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...).

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Could it be that you should have included a manifest file that names the class
    containing the main method ?
    eschew obfuscation

  3. #3
    Join Date
    Apr 2005
    Posts
    18
    O.K. The web page I looked at for instructions on creating jar files didn't mention me having to create a manifest file first. I'll search around some more.

    Thanks.

    UPDATE
    I tried making a manifest file. I called it "mainClass.txt" and I put the line "Main-Class: HexDisplay.class" in it (I also tried not puting the extension on HexDisplay). Then in command prompt I typed "jar cvmf mainClass.txt
    HexMaze.jar *.class":
    C:\Documents and Settings\Aaron MacDonald\Desktop\hexMaze>jar cvmf mainClass.txt
    HexMaze.jar *.class
    added manifest
    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>
    This made HexMaze.jar appear in my folder, but I get the exact same error I got before when I try to open it!
    Last edited by AaronJM; 06-07-2005 at 01:38 PM.

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Ok, i think the manifest file should have an .mf extension, I have made an executable
    jar file from my 'cfe' package, the class with the main in is named App, and the
    manifest file is named

    manifest.mf

    and its contents are:
    Code:
    Manifest-Version: 1.0
    Main-Class: cfe.App
    eschew obfuscation

  5. #5
    Join Date
    Apr 2005
    Posts
    18

    Angry

    Nope, still doen't work.

    I put this in my manifest file:
    Manifest-Version: 1.0
    Main-Class: hexMaze.HexDisplay
    Then I tried to make the jar like I did last time, but I got a "IOException: invalid header field". I tried taking out the line with "Manifest-Version: 1.0" and I got a jar file, but that error is still there.

  6. #6
    Join Date
    Dec 2003
    Location
    tx/us
    Posts
    131
    I've exported runnable jars out of Eclipse. There's a place in the export dialog sequence where you tell it to generate a manifest and you pick the class containing main().

  7. #7
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    There you go
    eschew obfuscation

  8. #8
    Join Date
    Apr 2005
    Posts
    18

    Smile

    The Eclipse method worked perfectly. I didn't notice that field where you specify the main class (you have to click "next" twice). Thanks ray326.

  9. #9
    Join Date
    Dec 2003
    Location
    tx/us
    Posts
    131
    (you have to click "next" twice)
    Finishing too soon is always a bad thing, or so I'm told.

  10. #10
    Join Date
    Apr 2006
    Posts
    4

    manifest problem

    hi,

    just update mail-class in manifest and give class path for external needed jar files.

    put lib folder in your jar file folder(like dist folder and) and put your other jar files and related folders). This may help u.

  11. #11
    Join Date
    Oct 2006
    Posts
    5

    Arrow 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: -

    Main-Class: <mainClass>

    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

    Main-Class: HexDisplay
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center