Can't execute jar- file: “no main manifest attribute”

后端 未结 30 1939
不知归路
不知归路 2020-11-21 22:30

I have installed an application, when I try to run it (it\'s an executable jar) nothing happens. When I run it from the commandline with:

java -jar \

相关标签:
30条回答
  • 2020-11-21 22:41

    The above answers were only partly helpful for me. java -cp was part of the answer, but I needed more specific info on how to identify the class to run. Here is what worked for me:

    Step 1: find the class I need to run

    jar tf /path/to/myjar.jar | more
    

    The top lines of the result were:

    META-INF/
    META-INF/MANIFEST.MF
    somepath/
    somepath/App.class
    META-INF/maven/
    ...
    

    App.class contained the main class to run. I'm not 100% sure if you can always assume the class you need is the first one, but it was for me. If it isn't, I'd imagine it isn't too hard to use grep to exclude library-related results to pare the class list down to a manageable size.

    From there it was easy: I just use that path (minus the ".class" suffix):

    java -cp /path/to/myjar.jar somepath/App
    
    0 讨论(0)
  • 2020-11-21 22:43

    I had the same issue today. My problem was solved my moving META-INF to the resources folder.

    0 讨论(0)
  • 2020-11-21 22:44

    I found a new solution to bad manifest generation !

    1. Open the jar file with a zip editor like WinRAR
    2. Click on for META-INF

    3. Add or edit

      • Add:

        • Create a text file called MANIFEST.MF in a folder called META-INF and add the following line:

          • Manifest-Version: 1.0
          • Main-Class: package.ex.com.views.mainClassName
        • Save the file and add it to the zip

      • Edit:

        • Drag the file out modify the MANIFEST.MF to add the previous line
    4. Open cmd and type: java -jar c:/path/JarName.jar

    It should work fine now !

    0 讨论(0)
  • 2020-11-21 22:45

    The Gradle answer is to add a jar/manifest/attributes setting like this:

    apply plugin: 'java'
    
    jar {
        manifest {
            attributes 'Main-Class': 'com.package.app.Class'
        }
    }
    
    0 讨论(0)
  • 2020-11-21 22:45

    Any executable jar file Should run either by clicking or running using command prompt like java -jar app.jar (use "if path of jar contains space" - i.e. java -jar "C:\folder name\app.jar"). If your executable jar is not running, which means it is not created properly.

    For better understanding, extract the jar file (or view using any tool, for windows 7-Zip is nice one) and check the file under /META-INF/MANIFEST.MF. If you find any entry like

    Main-Class: your.package.name.ClaaswithMain - then it's fine, otherwise you have to provide it.

    Be aware of appending Main-Class entry on MANIFEST.MF file, check where you are saving it!

    0 讨论(0)
  • 2020-11-21 22:46

    If using Maven, include following in the pom

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
    </parent>
    
    <properties>
        <java.version>1.8</java.version>
    </properties>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    
    0 讨论(0)
提交回复
热议问题