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

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

    The easiest way to be sure that you have created the runnable JAR file correctly, with the appropriate manifest file, is to use Eclipse to build it for you. In your Eclipse project, you basically just select File/Export from the menu, and follow the prompts.

    That way, you can be sure that your JAR file is correct and will know to look elsewhere if there is still an issue. The process is described in full in FAQ How do I create an executable JAR file for a stand-alone SWT program?.

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

    You can run with:

    java -cp .;app.jar package.MainClass
    

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

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

    I was getting the same error when i ran:
    jar cvfm test.jar Test.class Manifest.txt

    What resolved it was this:
    jar cvfm test.jar Manifest.txt Test.class

    My manifest has the entry point as given in oracle docs (make sure there is a new line character at the end of the file):
    Main-Class: Test

    0 讨论(0)
  • 2020-11-28 05:05
    1. set the classpath and compile

      javac -classpath "C:\Program Files\Java\jdk1.6.0_updateVersion\tools.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

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

    I discovered that I was also having this error in NetBeans. I hope the following is helpful.

    1. Make sure that when you go to Project Configuration you set the main class you intend for running.
    2. Do a Build or Clean Build
    3. Place the jar file where you wish and try: java -jar "YourProject.jar" again at the command line.

    This was the problem I was getting because I had other "test" programs I was using in NetBeans and I had to make sure the Main Class under the Run portion of the Project configuration was set correctly.

    many blessings, John P

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

    If you using eclipse, try below: 1. Right click on the project -> select Export 2. Select Runnable Jar file in the select an export destination 3. Enter jar's name and Select "Package required ... " (second radio button) -> Finish

    Hope this helps...!

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