大家都知道spring boot有个很吸引人的特性,那就是可以直接把应用打包成为一个jar/war,而且这个jar/war是可以直接启动的,称之为“fat jar”。
但是有时候我们有这样的需求:
- 1.将项目中通常版本号确定不会用什么变动的依赖包,不打包进运行包,而是放到外部某个文件夹中,在启动运行包时,再去读取加载
- 2.经常需要变动的项目模块打包进运行包
这样做的好处:运行包显著变小,传递更加快捷,在经常需要变更的环境下非常有用处!
关于“fat jar”启动不清楚的,可以参考:http://blog.csdn.net/hengyunabc/article/details/50120001,可能和当前版本有些出入,但基本原理是这样。
1.”fat jar” to “thin jar”
1)添加配置:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.4.0.RELEASE</version>
<configuration>
<layout>ZIP</layout>
<executable>true</executable>
<includes>
<include>
<groupId>nothing</groupId>
<artifactId>nothing</artifactId>
</include>
<include>
<groupId>org.cyzy</groupId>
<artifactId>common</artifactId>
</include>
</includes>
</configuration>
</plugin>
layout
设置为ZIP,此模式下spring-boot-maven-plugin会将Manifest.MF文件中的Main-Class设置为org.springframework.boot.loader.PropertiesLauncher。
PropertiesLauncher源码注释:
Launcher for archives with user-configured c