1. pom.xml
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<!-- 主类 -->
<mainClass>com.deem.zkui.Main</mainClass>
</manifest>
</archive>
<descriptors>
<!-- 打包描述文件 -->
<descriptor>release.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
2. release.xml
<assembly>
<baseDirectory>zk-ui</baseDirectory>
<formats>
<!-- 输出类型 -->
<format>dir</format>
<format>tar.gz</format>
</formats>
<!-- 包含根目录,即解压之后,会有上面的zk-ui目录 -->
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<!-- 输出目录,相对baseDirectory -->
<outputDirectory>/</outputDirectory>
<includes>
<!-- 包含文件 -->
<include>log4j.properties</include>
<include>config.cfg</include>
</includes>
</fileSet>
</fileSets>
<files>
<file>
<!-- 包含jar包,使用此种方式不包含target目录,如果使用上面fileSet的方式,会包含target目录 -->
<source>target/zkui-2.0-SNAPSHOT.jar</source>
</file>
</files>
</assembly>
3. 注意事项
经过测试,如果maven项目中有子项目。不能在父项目的pom中配置descriptor,需要新建一个子项目专门用来打包。举例:如果有父项目A,子项目B和C继承A,那么如果需要打包所有项目的jar包以及conf等目录,必须新建一个项目D继承A,在项目D中配置maven-assembly-plugin和descriptor。