关于spring boot web工程打jar包运行报主清单属性错误解决
.jar中没有主清单属性
先说解决方法
在项目的pom.xml中添加打包插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<!--可以把依赖的包都打包到生成的Jar包中-->
<goal>repackage</goal>
</goals>
<configuration>
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
原因:若没有添加这个插件,那么maven将会把项目打成普通的jar包,而普通的jar怎么会有spring boot的入口配置呢
入口程序配置,在jar包中的
META-INF/MANIFEST.MF
Manifest-Version: 1.0
Implementation-Title: XXX_eureka
Implementation-Version: 1.0-SNAPSHOT
Built-By: XXX
Implementation-Vendor-Id: com.XXX
Created-By: Apache Maven 3.8.1
Build-Jdk: 1.8.0_201
Implementation-URL: https://projects.spring.io/spring-boot/#/spring-bo
ot-starter-parent/xxx_parent/XXX_eureka
而且也没有将项目所依赖的jar包导入项目中。
而添加了插件后,maven就会将依赖以及启动入口添加到项目jar中。
在解压jar包后就会看到org的文件,且META-INF/MANIFEST.MF的配置将会多出启动入口,即主属性配置信息
其中包含:Main-Class、Start-Class等等入口信息。
Manifest-Version: 1.0
Implementation-Title: XXX_eureka
Implementation-Version: 1.0-SNAPSHOT
Built-By: xxx
Implementation-Vendor-Id: com.XXX
Spring-Boot-Version: 2.1.4.RELEASE
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.XXX.eureka.EurekaApplication
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Created-By: Apache Maven 3.8.1
Build-Jdk: 1.8.0_201
Implementation-URL: https://projects.spring.io/spring-boot/#/spring-bo
ot-starter-parent/XXX_parent/XXX_eureka