使用assembly将maven项目pom.xml中的jar包打包

方法一:将pom.xml引入的jar包打到zip文件夹中

  1、pom.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
<!-- 打包配置 start -->
     < build >
         < plugins >
             < plugin >
                 <!-- NOTE: We don't need a groupId specification because the group is
                     org.apache.maven.plugins ...which is assumed by default. -->
                 < artifactId >maven-assembly-plugin</ artifactId >
                 < version >2.4</ version >
                 < configuration >
                     < descriptors >
                         < descriptor >src/main/assembly/src.xml</ descriptor >
                     </ descriptors >
                     < descriptorRefs >
                         < descriptorRef >jar-with-dependencies</ descriptorRef >
                     </ descriptorRefs >
                 </ configuration >
                 < executions >
                     < execution >
                         < id >make-assembly</ id <!-- this is used for inheritance merges -->
                         < phase >package</ phase <!-- bind to the packaging phase -->
                         < goals >
                             < goal >single</ goal >
                         </ goals >
                     </ execution >
                 </ executions >
             </ plugin >
         </ plugins >
     </ build >

  2、src.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
     < id >package</ id >
     < formats >
         < format >zip</ format >
     </ formats >
     < includeBaseDirectory >true</ includeBaseDirectory >
     < fileSets >
         < fileSet >
             < directory >src/main/bin</ directory >
             < outputDirectory >/</ outputDirectory >
         </ fileSet >
         < fileSet >
             < directory >src/main/config</ directory >
             < outputDirectory >config</ outputDirectory >
         </ fileSet >
     </ fileSets >
     < dependencySets >
         < dependencySet >
             < outputDirectory >lib</ outputDirectory >
             < scope >runtime</ scope >
         </ dependencySet >
     </ dependencySets >
</ assembly >

  方法1能把所有引入的包打成jar包,方便自己保存和引入。

  3、最后一步

  cmd进入在项目根目录下,键入“mvn package”,OK完事!

方法二:将pom引入的jar包打进你的项目工程jar包内

  1、pom.xml的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!-- 打包配置 start -->
     < build >
         <!-- <finalName>im-dal-service</finalName>
         <sourceDirectory>src/main/java</sourceDirectory>
         <resources>
             控制资源文件的拷贝
             <resource>
                 <directory>src/main/resources</directory>
                 <targetPath>${project.build.directory}</targetPath>
             </resource>
         </resources> -->
         < plugins >
             < plugin >
                 < artifactId >maven-assembly-plugin</ artifactId >
                 < configuration >
                     < descriptors >
                         < descriptor >src/main/assembly/src.xml</ descriptor >
                     </ descriptors >
                 </ configuration >
             </ plugin >
         </ plugins >
 
     </ build >

  2、src.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<? xml  version="1.0" encoding="UTF-8"?>
   < id >jar-with-dependencies</ id >
   < formats >
     < format >jar</ format >
   </ formats >
   < includeBaseDirectory >false</ includeBaseDirectory >
   < dependencySets >
     < dependencySet >
       < unpack >false</ unpack >
       < scope >runtime</ scope >
     </ dependencySet >
   </ dependencySets >
   < fileSets >
     < fileSet >
       < directory >/lib</ directory >
     </ fileSet >
   </ fileSets >
</ assembly >

  3、最后一步

  cmd进入在项目根目录下,键入“mvn assembly:assembly”,OK完事!


转自:http://www.cnblogs.com/enshrineZither/p/3402616.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值