javamavennetbeansjarmanifest.mf

"No Main Manifest Attribute" in ----.jar Netbeans


I recently just started toying around with Maven in java. Time comes to test my project, it works fine in the NetBeans window, running the main class found in App.java (com.MyCompany.App), but when I try to run it from a command line I get an error:

java -jar fileName.jar

"No Main Manifest Attribute" in fileName.jar

I have tried adding a manifest.mf file specifying what main is, I've also been into project properties and added it as the main file...

What's going on?


Solution

  • Hope there is a problem in your manifest file. Some basic checks might solve your problem.

    If you are using any IDE, there should be an option to export project as runnable jar, you can make use of that to let the IDE take care of correct manifest.

    From command line jar cfm filename.jar Manifest.txt com/MyCompany/*.class which generates the Manifest file with following contents

    Manifest-Version: 1.0
    Created-By: 1.6.0 (Sun Microsystems Inc.)
    Main-Class: com.MyCompany.App
    

    And then you can run jar command java -jar fileName.jar.

    These type of problems are trivial but kills lot of time, just ensure your contents and location of the file is correct.