jar run error no main manifest attribute

Run on the server:

java -jar test-0.0.1-SNAPSHOT.jar

Error:

no main manifest attribute, in test-0.0.1-SNAPSHOT.jar

the reason:

The reason is that the main class cannot be found.

In general, to package java into a jar package, you need to specify the Main-Class item in MANIFEST.MF so that the corresponding main class can be found when running java -jar xxx.jar.

After decompressing test-0.0.1-SNAPSHOT.jar,
Insert picture description here
check the MANIFEST.MF under META-INF

Insert picture description here
Insert picture description here
The normal one should look like this:
Insert picture description here

solve:

After investigation, it was found that the pom.xml
in the maven project was not added

<packaging>jar</packaging>

Also don't forget spring-boot-maven-plugin

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

After adding these two, just pack and run.

Guess you like

Origin blog.csdn.net/qq_33697094/article/details/110549536