java – Why has it failed to load main-class manifest attribute from a JAR file?

java – Why has it failed to load main-class manifest attribute from a JAR file?

Im not sure I believe your symptoms:

  • If the jre command isnt found, then running jre -cp app.jar should give the same error
  • Just adding a JAR file to the classpath shouldnt give the error youre seeing

Id expect you to see this error if you run:

java -jar app.jar

The Main-Class header needs to be in the manifest for the JAR file – this is metadata about things like other required libraries. See the Sun documentation for how to create an appropriate manifest. Basically you need to create a text file which includes a line like this:

Main-Class: MainClass

Then run

jar cfm app.jar manifest.txt *.class
  1. set the classpath and compile

    javac -classpath C:Program FilesJavajdk1.6.0_updateVersiontools.jar yourApp.java

  2. create manifest.txt

    Main-Class: yourApp newline

  3. create yourApp.jar

    jar cvf0m yourApp.jar manifest.txt yourApp.class

  4. run yourApp.jar

    java -jar yourApp.jar

java – Why has it failed to load main-class manifest attribute from a JAR file?

You can run with:

java -cp .;app.jar package.MainClass

It works for me if there is no manifest in the JAR file.

Leave a Reply

Your email address will not be published.