Maven assembly plugin for dependency zip
程序员文章站
2022-05-10 14:29:55
...
最近需要将项目进行打包,本来使用默认的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 |
推荐阅读
-
解决maven-dependency-plugin (goals "copy-dependencies","unpack") is not supported
-
解决maven-dependency-plugin (goals "copy-dependencies","unpack") is not supported
-
打包的插件有maven的jar,war(可执行),还有assembly插件(zip)
-
maven-dependency-plugin插件
-
maven-dependency-plugin插件
-
Maven maven-dependency-plugin (goals "copy-dependencies", "unpack") is not suppo
-
Maven maven-dependency-plugin (goals "copy-dependencies", "unpack") is not suppo
-
Maven 使用maven-assembly-plugin打包可执行jar,No auto configuration classes found in META-INF/spring.factori
-
初学maven(5)-使用assembly plugin实现自定义打包
-
解决maven-assembly-plugin descriptor 乱码