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

后端 未结 11 1380
不思量自难忘°
不思量自难忘° 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:13

    I got this error, and it was because I had the arguments in the wrong order:

    CORRECT

    java maui.main.Examples tagging -jar maui-1.0.jar 
    

    WRONG

    java -jar maui-1.0.jar maui.main.Examples tagging 
    
    0 讨论(0)
  • 2020-11-28 05:16

    Try

    java -cp .:mail-1.4.1.jar JavaxMailHTML 
    

    no need to have manifest file.

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2020-11-28 05:22

    I faced the same problem. This unix command is not able to find the main class. This is because the runtime and compile time JDK versions are different. Make the jar through eclipse after changing the java compiler version. The following link helped me.

    http://crunchify.com/exception-in-thread-main-java-lang-unsupportedclassversionerror-comcrunchifymain-unsupported-major-minor-version-51-0/

    Try running the jar created after this step and then execute it

    0 讨论(0)
  • 2020-11-28 05:23

    If your class path is fully specified in manifest, maybe you need the last version of java runtime environment. My problem fixed when i reinstalled the jre 8.

    0 讨论(0)
提交回复
热议问题