一段实用的maven pom:将项目依赖打包到文件夹或打入jar中

使用了maven-assembly-plugin插件和maven-dependency-plugin:

[html]  view plain  copy
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">    
  3.     <modelVersion>4.0.0</modelVersion>    
  4.     <groupId>net.aty.deps</groupId>    
  5.     <artifactId>MyJar</artifactId>    
  6.     <packaging>jar</packaging>    
  7.     <version>0.0</version>    
  8.     
  9.     <dependencies>    
  10.         <dependency>  
  11.             <groupId>org.apache.httpcomponents</groupId>  
  12.             <artifactId>httpclient</artifactId>  
  13.             <version>4.3.6</version>  
  14.         </dependency>  
  15.     </dependencies>    
  16.     
  17.     <build>    
  18.         <plugins>   
  19.               
  20.             <plugin>  
  21.                 <groupId>org.apache.maven.plugins</groupId>  
  22.                 <artifactId>maven-dependency-plugin</artifactId>  
  23.                 <executions>  
  24.                     <execution>  
  25.                         <id>copy-dependencies</id>  
  26.                         <phase>prepare-package</phase>  
  27.                         <goals>  
  28.                             <goal>copy-dependencies</goal>  
  29.                         </goals>  
  30.                         <configuration>  
  31.                             <outputDirectory>${project.build.directory}/lib</outputDirectory>  
  32.                             <overWriteReleases>false</overWriteReleases>  
  33.                             <overWriteSnapshots>false</overWriteSnapshots>  
  34.                             <overWriteIfNewer>true</overWriteIfNewer>  
  35.                         </configuration>  
  36.                     </execution>  
  37.                 </executions>  
  38.             </plugin>  
  39.               
  40.               
  41.             <plugin>    
  42.                 <artifactId>maven-assembly-plugin</artifactId>    
  43.                 <configuration>    
  44.                     <descriptorRefs>    
  45.                         <descriptorRef>jar-with-dependencies</descriptorRef>    
  46.                     </descriptorRefs>    
  47.                     <archive>    
  48.                         <manifest>    
  49.                           <mainClass></mainClass>    
  50.                         </manifest>    
  51.                     </archive>    
  52.                 </configuration>    
  53.                 <executions>    
  54.                     <execution>    
  55.                         <id>make-assembly</id>    
  56.                         <phase>package</phase>    
  57.                         <goals>    
  58.                             <goal>single</goal>    
  59.                         </goals>    
  60.                     </execution>    
  61.               </executions>    
  62.             </plugin>   
  63.               
  64.         </plugins>  
  65.     </build>    
  66. </project>   



执行mvn clean package命令,我们就可以得到如下结果:

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值