這可以使用maven-assembly-plugin
。這是一個非常通用的插件,可以用來創建項目的自定義組件。
它通過assembly.xml
文件進行配置。對於你的情況下,配置是:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>dist</id>
<formats>
<format>zip</format> <!-- create a zip archive -->
</formats>
<fileSets>
<fileSet>
<directory>dist</directory> <!-- source is the "dist" folder -->
<outputDirectory>/</outputDirectory> <!-- target is the root of the archive -->
</fileSet>
</fileSets>
</assembly>
此文件的典型位置將是src/main/assembly/assembly.xml
。然後,POM將包含:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>assembly-dist</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
調用mvn clean package
後,target
文件夾將包含此插件生成的壓縮文件。