上次写了篇 《SpringBoot迭代发布JAR瘦身配置》,但有一个问题,全部的第三方JAR位于lib目录中,不利于传输到服务器,所以应该考虑将此目录压缩打包,再传输到服务器,服务器解压便可使用。html
通过一番google,找到相似的plugin(maven-assembly-plugin),看官网的介绍:spring
The Assembly Plugin for Maven is primarily intended to allow users to aggregate the project output along with its dependencies, modules, site documentation, and other files into a single distributable archive.
大体意思就是:Assembly Plugin 主要是为了容许用户将项目输出及其依赖项、模块、文档和其余文件聚合到一个可发布的文件中。通俗一点就是能够定制化本身想要打包的文件,支持打包的格式有:zip、tar、tar.gz (or tgz)、tar.bz2 (or tbz2)、tar.snappy、tar.xz (or txz)、jar、dir、war。apache
接下来我就根据本身的需求定制我想要的包,我想把 target/lib 目录压缩打包,服务器
<!-- lib 文件夹压缩打包 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <configuration> <finalName>${project.artifactId}-libs</finalName> <encoding>UTF-8</encoding> <descriptors> <descriptor>assembly.xml</descriptor> </descriptors> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/3.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/3.1.0 http://maven.apache.org/xsd/assembly-3.1.0.xsd"> <formats> <format>tar.gz</format> </formats> <id>${project.version}</id> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>target/lib</directory> <outputDirectory>lib</outputDirectory> </fileSet> </fileSets> </assembly>
到此,配置就写完了,执行打包命令:mvn clean package -Dmaven.test.skip=true,就能够在target目录下看到咱们的压缩文件:app
组合上篇 《SpringBoot迭代发布JAR瘦身配置》的配置,就能够实现把spring boot 项目打包成thin jar 以及把第三方jar打成压缩文件。固然,我这里用maven-assembly-plugin,根本就是大材小用,还有点违背此plugin的初衷,我只是取巧了而已。另外,若是用jenkins发布的话,用命令将lib目录压缩打包也是能够的,有时候解决问题的办法不少不少,任君选择!maven