目的
将jar包、sh安装文件和sql脚本文件一起压缩成zip包,可直接上传linux部署
多环境配置
测试环境和生成环境配置,配置文件:pom.xml
<profiles>
<profile>
<!-- 唯一标识:test===测试环境 -->
<id>test</id>
<!-- 属性配置-自定义 -->
<properties>
<!-- 传递给脚本的参数-标签名自定义,作为取值的变量名 -->
<activeProfile>test</activeProfile>
</properties>
<activation>
<!-- 指定默认配置文件 -->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<!-- 唯一标识 -->
<id>prod</id>
<!-- 属性配置-自定义 -->
<properties>
<!-- 传递给脚本的参数-标签名自定义,作为取值的变量名 -->
<activeProfile>prod</activeProfile>
</properties>
</profile>
</profiles>
Assembly打包配置
maven-assembly-plugin
maven插件配置,配置文件:pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptors>
<!-- assembly.xml配置文件路径 -->
<descriptor>
${project.basedir}/src/main/resources/assembly/assembly.xml
</descriptor>
</descriptors>
<finalName>${artifactId}</finalName>
</configuration>
<executions>
<execution> <!-- 执行器 mvn assembly:assembly -->
<id>make-assembly</id> <!-- 名字任意 -->
<phase>package</phase> <!-- 绑定到package生命周期 -->
<goals>
<goal>single</goal> <!-- 该打包任务只运行一次 -->
</goals>
</execution>
</executions>
</plugin>
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
http://maven.apache.org/ASSEMBLY/2.0.0 ">
<id>${project.version}</id>
<!--打包成一个用于发布的zip文件-->
<formats>
<format>zip</format>
</formats>
<!--true:zip中生成一级目录(此处屏蔽,配合脚本需要profiles后缀)-->
<includeBaseDirectory>true</includeBaseDirectory>
<baseDirectory>${project.artifactId}-${project.version}</baseDirectory>
<fileSets>
<!-- 配置文件打包进zip文件的conf目录 -->
<fileSet>
<directory>${project.basedir}/src/main/resources</directory>
<outputDirectory>conf</outputDirectory>
<includes>
<!-- <include>**/*</include> -->
<!-- 配置文件名称,如application-test.yml -->
<include>*-${activeProfile}.yml</include>
</includes>
</fileSet>
<!--启动脚本打包进zip文件-->
<fileSet>
<directory>${project.basedir}/sh</directory>
<outputDirectory></outputDirectory>
<includes>
<include>**/*</include>
</includes>
<!-- 文件文件权限为777 -->
<fileMode>777</fileMode>
<!-- 目录权限为777 -->
<directoryMode>777</directoryMode>
<!--脚本中参数变量为pom中的值关键-->
<filtered>true</filtered>
</fileSet>
<!-- 项目编译出来的jar打包进zip文件 -->
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>