<properties>
<project.finalName>finalName</project.finalName>
<env>dev</env>
</properties>
<build>
<finalName>${project.finalName}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- 根据输入参数动态修改相关内容 -->
<filtering>true</filtering>
<!-- 资源根目录排除各环境的配置,防止在生成目录中多余其它目录 -->
<excludes>
<exclude>dev/**</exclude>
<exclude>test/**</exclude>
<exclude>pro/**</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources/${env}</directory>
<!-- 根据输入参数动态修改相关内容 -->
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- 配置文件转移到config目录 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<!-- 表示把配置文件拷到和jar包同一个路径下 -->
<outputDirectory>
${project.build.directory}/conf
</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/classes</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- The configuration of maven-jar-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<!--生成的jar中不包含pom.xml和pom.properties这两个文件-->
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<!--是否要把第三方jar放到manifest的classpath中-->
<addClasspath>true</addClasspath>
<!--生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/-->
<classpathPrefix>lib/</classpathPrefix>
<!--应用的main class-->
<mainClass>***</mainClass>
<!-- MANIFEST.MF文件添加SNAPSHOT依赖包的时候,不带时间戳,直接使用SNAPSHOT -->
<useUniqueVersions>false</useUniqueVersions>
</manifest>
<manifestEntries>
<Class-Path>./conf/</Class-Path>
</manifestEntries>
</archive>
<!--过滤掉不希望包含在jar中的文件-->
<excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.xml</exclude>
</excludes>
</configuration>
</plugin>
<!-- 配置依赖jar打包到lib目录 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- assembly配置 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<!-- The configuration of the plugin -->
<configuration>
<!-- Specifies the configuration file of the assembly plugin -->
<descriptors>
<descriptor>src/main/assembly-package.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 不打包test代码 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
assembly-package.xml放到项目main目录下
<assembly>
<id>bin</id>
<!-- 最终打包成一个用于发布的zip文件 -->
<formats>
<format>zip</format>
</formats>
<fileSets>
<!-- 把项目相关的说明文件,打包进zip文件的根目录 -->
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
<!-- 把项目的配置文件,打包进zip包的conf目录 -->
<fileSet>
<directory>${project.build.directory}/conf</directory>
<outputDirectory>/${project.build.finalName}/conf</outputDirectory>
<directoryMode>0755</directoryMode>
<fileMode>0644</fileMode>
</fileSet>
<!-- 把项目依赖的jar包,打包进zip包的lib目录 -->
<fileSet>
<directory>${project.build.directory}/lib</directory>
<outputDirectory>/${project.build.finalName}/lib</outputDirectory>
<directoryMode>0755</directoryMode>
<fileMode>0644</fileMode>
</fileSet>
<!-- 把项目编译的jar包,打包进zip包的根目录 -->
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/${project.build.finalName}</outputDirectory>
<includes>
<include>${project.build.finalName}.jar</include>
</includes>
</fileSet>
<!-- 把项目的脚本文件,打包进zip包的bin目录 -->
<fileSet>
<directory>${project.basedir}/src/bin</directory>
<outputDirectory>/bin</outputDirectory>
<directoryMode>0755</directoryMode>
<fileMode>0755</fileMode>
<lineEnding>unix</lineEnding>
<includes>
<include>**/*.sh</include>
<include>*.cfg</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/bin</directory>
<outputDirectory>/bin</outputDirectory>
<directoryMode>0755</directoryMode>
<fileMode>0755</fileMode>
<lineEnding>dos</lineEnding>
<includes>
<include>*.bat</include>
</includes>
</fileSet>
</fileSets>
</assembly>