启动springboot项目时,出现以下异常
no main manifest attribute, in ./XXX.jar
这是因为启动jar包时,未找到主类

解决: 使用spring-boot-maven-plugin插件,在pom.xml配置以下内容
-
-
-
org.springframework.boot -
spring-boot-maven-plugin -
2.5.0 -
-
-
-
repackage -
-
-
-
-
主类全名 -
-
-
-
需要注意一点,spring-boot-maven-plugin尽量选择高版本,(2.3.12.RELEASE)低版本可以打包成功,但是启动时依旧找不到主类。
目前最新版本已经是2.7.2了,项目里面使用,要跟spring-boot-starter-web版本尽量保持一致,后续升级也好管理。

在pom.xml配置好spring-boot-maven-plugin,先clean、后package即可完成打包

如果不使用spring-boot-maven-plugin插件怎么打包?
1、使用maven-shade-plugin,配置之后执行mvn clean package就OK了。
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-compiler-pluginartifactId>
- <version>3.8.0version>
- <configuration>
- <source>1.8source>
- <target>1.8target>
- configuration>
- plugin>
-
- <plugin>
- <groupId>org.apache.maven.pluginsgroupId>
- <artifactId>maven-shade-pluginartifactId>
- <version>3.2.1version>
- <executions>
- <execution>
- <phase>packagephase>
- <goals>
- <goal>shadegoal>
- goals>
- <configuration>
- <transformers>
- <transformer
- implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
- <mainClass>com.cn.dl.main.ApplicationJobmainClass>
- transformer>
- <transformer
- implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
- <resource>META-INF/spring.handlersresource>
- transformer>
- <transformer
- implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
- <resource>META-INF/spring.schemasresource>
- transformer>
- transformers>
- configuration>
- execution>
- executions>
- plugin>
- plugins>
- build>
2、使用maven-assembly-plugin插件,然后执行mvn clean assembly:assembly
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.pluginsgroupId>
- <artifactId>maven-jar-pluginartifactId>
- <version>3.1.0version>
- plugin>
- <plugin>
- <artifactId>maven-assembly-pluginartifactId>
- <configuration>
- <descriptorRefs>
- <descriptorRef>jar-with-dependenciesdescriptorRef>
- descriptorRefs>
- <archive>
- <manifest>
- <mainClass>com.cn.dl.main.ApplicationJobmainClass>
- manifest>
- archive>
- configuration>
- plugin>
- plugins>
- build>