pom.xml
<build>
<plugins>
<!-- 使用spring boot的maven插件进行打包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- 是否打出可执行的jar包(仅支持Linux格式) -->
<executable>false</executable>
</configuration>
</plugin>
<!-- 将jar包和外部配置等文件整体打包(zip,tar,tar.gz等) -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<!--jar包名称-->
<finalName>${project.artifactId}-${project.version}</finalName>
</configuration>
<executions>
<execution>
<id>full</id>
<!-- 绑定到package生命周期阶段上 -->
<phase>package</phase>
<goals>
<!-- 只运行一次 -->
<goal>single</goal>
</goals>
<configuration>
<!--描述文件路径-->
<descriptor>${basedir}/assembly/assembly.xml</descriptor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
配置比较多而且比较固定,所以可以在parent工程中声明,在要打包的项目中引用。
assembly.xml 配置
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<!--这个id会跟在打包文件后面,现还不清楚怎么取消-->
<id>jar</id>
<formats>
<format>tar.gz</format>
</formats>
<fileSets>
<fileSet>
<!--打包时把/resources/config 目录内的文件放在jar包外的/目录下-->
<directory>${project.build.directory}/classes/config</directory>
<outputDirectory>/</outputDirectory>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
<files>
<!--打包时把README.md文件放在jar包外-->
<file>
<source>README.md</source>
<outputDirectory></outputDirectory>
</file>
<file>
<!--打好的jar包名称和放置目录-->
<source>${project.build.directory}/${project.build.finalName}.jar</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
</assembly>