最近需要將項目進行打包,本來使用默認的maven-dependency-plugin 就足夠了,但是現在需要一些自定義的處理,需要將依賴的包打入lib目錄,同時將main class jar與lib文件夾一起壓縮成zip包。
這時候maven-dependency-plugin就不管用了,需要上maven-assembly-plugin了。
目標文件目錄
+helloworld.zip
helloworld.jar
+lib/
dependency1.jar
dependency1.jar
POM配置
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
|
< plugin >
< artifactId >maven-jar-plugin</ artifactId >
< configuration >
< archive >
< manifest >
< addClasspath >true</ addClasspath >
< classpathPrefix >lib/</ classpathPrefix >
< mainClass >xxx.MainJob</ mainClass >
</ manifest >
</ archive >
< finalName >${project.artifactId}-${env}-${project.version}</ finalName >
</ configuration >
</ plugin >
< plugin >
< groupId >org.apache.maven.plugins</ groupId >
< artifactId >maven-assembly-plugin</ artifactId >
< configuration >
< descriptors >
< descriptor >assembly.xml</ descriptor >
</ descriptors >
</ configuration >
< executions >
< execution >
< id >make-assembly</ id >
< phase >package</ phase >
< goals >
< goal >single</ goal >
</ goals >
</ execution >
</ executions >
</ plugin >
|
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
|
< assembly xmlns = "http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd" >
< id ></ id >
< formats >
<!--<format>tar.gz</format>-->
<!--<format>tar.bz2</format>-->
< format >zip</ format >
</ formats >
< fileSets >
< fileSet >
< directory >${project.basedir}</ directory >
< outputDirectory >/</ outputDirectory >
< includes >
< include >README*</ include >
< include >LICENSE*</ include >
< include >NOTICE*</ include >
</ includes >
</ fileSet >
< fileSet >
< directory >${project.build.directory}/site</ directory >
< outputDirectory >docs</ outputDirectory >
</ fileSet >
< fileSet >
< directory >${project.build.directory}/</ directory >
< outputDirectory >/</ outputDirectory >
< includes >
< include >*.jar</ include >
</ includes >
</ fileSet >
</ fileSets >
< dependencySets >
< dependencySet >
< outputDirectory >/lib</ outputDirectory >
< useProjectArtifact >false</ useProjectArtifact >
< scope >runtime</ scope >
</ dependencySet >
</ dependencySets >
</ assembly >
|
執行命令
1
|
mvn package |