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

后端 未结 11 1435
不思量自难忘°
不思量自难忘° 2020-11-28 04:58

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



        
11条回答
  •  遥遥无期
    2020-11-28 05:18

    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
    

提交回复
热议问题