0%

assembly zip in maven

使用 maven-assembly-plugin,将项目打包成zip包.

1 pom.xml 添加 plugin 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptor>${project.basedir}/assembly.xml</descriptor>
<finalName>${project.build.finalName}</finalName>
<!-- 这里决定是否要加 assembly.xml 文件配置中的 <id> -->
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

2. 在 ${project.basedir}/assembly.xml 添加 assembly.xml 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<assembly>
<!-- if appendAssemblyId is true in plugin setting, the final zip filename will
be xxx-1.0.0.zip -->
<!-- the id -->
<id>${version}</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>

<fileSets>
<!-- pack jar into zip -->
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>${project.build.finalName}</outputDirectory>
<includes>
<include>${project.build.finalName}.jar</include>
</includes>
</fileSet>

<!-- pack scripts into zip -->
<fileSet>
<directory>${project.basedir}/packet/</directory>
<outputDirectory>${project.build.finalName}</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>

<!-- pack CHANGELOG.md into zip -->
<fileSet>
<directory>${project.basedir}/</directory>
<outputDirectory>${project.build.finalName}</outputDirectory>
<includes>
<include>CHANGELOG.md</include>
</includes>
</fileSet>

<!-- create empyt directory -->
<fileSet>
<outputDirectory>${project.build.finalName}/data</outputDirectory>
<excludes>
<exclude>**/*</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>

3 执行maven的package 命令,最后在 target/ 目录生成 zip包