Maven assembly实现自定义打包

来源:互联网 发布:团队办公软件 编辑:程序博客网 时间:2024/04/30 12:31

maven-assembly-plugin : 是maven中针对打包任务而提供的标准插件

(1)、在pom.xml 文件里面的配置说明

[html] view plain copy print?
  1. <plugin>  
  2.     <artifactId>maven-assembly-plugin</artifactId>  
  3.     <executions>  <!--执行器 mvn assembly:assembly-->  
  4.         <execution>  
  5.             <id>make-zip</id><!--名字任意 -->    
  6.         <phase>package</phase><!-- 绑定到package生命周期阶段上 -->    
  7.         <goals>    
  8.            <goal>single</goal><!-- 只运行一次 -->    
  9.         </goals>    
  10.             <configuration>  
  11.                      <descriptors> <!--描述文件路径-->  
  12.                           <descriptor>src/main/resources/zip.xml</descriptor>  
  13.                     </descriptors>  
  14.             </configuration>  
  15.         </execution>  
  16.     </executions>  
  17.  </plugin>  



(2)、zip.xml 文件配置如下

[html] view plain copy print?
  1. <assembly  
  2.     xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">  
  5.     <id>release</id>  
  6.     <formats>  
  7.         <format>zip</format>  
  8.     </formats>  
  9.     <fileSets>  
  10.         <fileSet>  
  11.             <directory>${project.basedir}\src\main\config</directory>  
  12.             <!-- 过滤 -->  
  13.             <excludes>  
  14.                 <exclude>*.xml</exclude>  
  15.             </excludes>  
  16.             <outputDirectory>\</outputDirectory>  
  17.         </fileSet>  
  18.     </fileSets>  
  19.       
  20.     <dependencySets>  
  21.         <dependencySet>  
  22.             <useProjectArtifact>true</useProjectArtifact>  
  23.             <outputDirectory>lib</outputDirectory><!-- 将scope为runtime的依赖包打包到lib目录下。 -->  
  24.             <scope>runtime</scope>  
  25.         </dependencySet>  
  26.     </dependencySets>  
  27. </assembly>  



 

(3)、zip.xml 格式属性说明

打包的文件格式
可以有:tar.zip war zip
< formats>
 <format>zip</format>
< /formats>

 

需要打包的路径
<directory>${project.basedir}</directory>

 

打包后输出的路径
<outputDirectory>/</outputDirectory>

 

打包需要包含的文件

 <excludes>
        <exclude>junit:junit</exclude>
        <exclude>commons-lang:commons-lang</exclude>
        <exclude>commons-logging:commons-logging</exclude>
< /excludes>

 

当前项目构件是否包含在这个依赖集合里。

<useProjectArtifact>true</useProjectArtifact>

 

依赖包打包到目录下
<dependencySets>
  <dependencySet>
   <outputDirectory>lib</outputDirectory><!-- 将scope为runtime的依赖包打包到lib目录下。 -->
   <useProjectArtifact>true</useProjectArtifact>
   <scope>runtime</scope>
  </dependencySet>
< /dependencySets>



原文地址:http://blog.csdn.net/cdl2008sky/article/details/6756177



0 0
原创粉丝点击