兼容 Spring 应用的 shade 配置,摘取自 Spring Boot Parent

spring-boot-maven-plugin 的作用:

The plugin rewrites your manifest, and in particular it manages the Main-Class and Start-Class entries, so if the defaults don't work you have to configure those there (not in the jar plugin). The Main-Class in the manifest is actually controlled by the layout property of the boot plugin, e.g.

实现方式: 在默认的maven-jar-plugin插件打包结束后,将项目依赖的jar包中的.class文件重新进行打包。并生成新的 MANIFEST.MF 文件。原非可执行 jar 命名为 xxx.jar.original, 可执行 JAR 叫做 xxx.jar

spring-boot-maven-plugin 作用就是使用自己实现插件的 Main-Class org.springframework.boot.loader.JarLauncher 进行资源加载,再通过用户声明的 start-class 启动应用程序

所以 Spring-Boot 应用与 maven shade 融合的过程中,会把 Main-Class 指定为 Start-Class ,就是把启动权还回了应用。

META-INF/MANIFEST.MF

Manifest-Version: 1.0
Implementation-Title: cpp
Implementation-Version: 0.0.1
Built-By: xuzeng
Implementation-Vendor-Id: com.lls.it.cpp
Spring-Boot-Version: 2.0.4.RELEASE
**Main-Class**: org.springframework.boot.loader.JarLauncher
**Start-Class**: com.lls.it.cpp.CppApplication
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Created-By: Apache Maven 3.5.4
Build-Jdk: 1.8.0_181
Implementation-URL: <https://projects.spring.io/spring-boot/#/spring-bo>
 ot-starter-parent/zeus_client/cpp