class manifest attribute from a JAR file?

I have created a JAR file in this way jar cf jar-file input-files . Now, I'm trying to run it. Running it does not work (jre command is not found):

jre -cp app.jar MainClass

This does not work either:

java -jar main.jar

(Failed to load Main-Class manifest attribute from main.jar).

I also found out that

To run an application packaged as a JAR file (version 1.2 -- requires Main-Class manifest header)

What is the "Main-Class manifest header"? How do I create it and where do I put it?


I'm not sure I believe your symptoms:

  • If the jre command isn't found, then running jre -cp app.jar should give the same error
  • Just adding a JAR file to the classpath shouldn't give the error you're seeing
  • I'd 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
    

  • set the classpath and compile

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

  • create manifest.txt

    Main-Class: yourApp newline

  • create yourApp.jar

    jar cvf0m yourApp.jar manifest.txt yourApp.class

  • run yourApp.jar

    java -jar yourApp.jar


  • You can run with:

    java -cp .;app.jar package.MainClass
    

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

    链接地址: http://www.djcxy.com/p/55018.html

    上一篇: 没有主要的清单属性,在jar中

    下一篇: 来自JAR文件的类清单属性?