Failed to load Main-Class manifest attribute while

2020-02-07 16:27发布

I have successfully built my Spring MVC project with mvn clean package by following this tutorial.

Now I am trying to run the service with:

mvn clean package && java -jar target/gs-serving-web-content-0.1.0.jar

But I get this error:

Failed to load Main-Class manifest attribute from target/gs-serving-web-content-0.1.0.jar

Am I missing something?

8条回答
混吃等死
2楼-- · 2020-02-07 17:05

For spring boot, I've created a MANIFEST.MF file inside META-INF folder.

in my STS IDE, I placed the META-INFO folder inside the src/main/resources folder like so:

screenshot from STS IDE (eclipse project)

the content of the MANIFEST.MF file:

Manifest-Version: 1.0
Implementation-Title: bankim
Implementation-Version: 1.5.6.RELEASE
Archiver-Version: Plexus Archiver
Built-By: Yourname
Implementation-Vendor-Id: com.bankim
Spring-Boot-Version: 1.5.6.RELEASE
Implementation-Vendor: Pivotal Software, Inc.
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.bankim.BankimApplication
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_131
Implementation-URL: http://projects.spring.io/spring-boot/bankim/
  1. Every mention of "bankim"/"Bankim" refers to my project name, so replace it with your project name that
  2. take special note of the "Start-Class" value. it should contain the "path" to the class that has your main method.
  3. the row: Main-Class: org.springframework.boot.loader.JarLaunchershould be left as-is.

****the above manifest was created for me by using the "spring-boot-maven-plugin" mentioned above by "Mradul Pandey" (answered Sep 2 '15 at 4:50)

Hope this helps

查看更多
贼婆χ
3楼-- · 2020-02-07 17:09

If you are working with Spring Boot this will solve your problem:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.2.5.RELEASE</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Reference Guide | Spring Boot Maven Plugin

查看更多
登录 后发表回答