读书人

Maven assembly兑现自定义打包(转)

发布时间: 2012-12-26 14:39:28 作者: rapoo

Maven assembly实现自定义打包(转)

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

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

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



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

[html] view plaincopy
  1. <assembly??????xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"??
  2. ????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">??
  3. ????<id>release</id>??????<formats>??
  4. ????????<format>zip</format>??????</formats>??
  5. ????<fileSets>??????????<fileSet>??
  6. ????????????<directory>${project.basedir}\src\main\config</directory>??????????????<!--?过滤?-->??
  7. ????????????<excludes>??????????????????<exclude>*.xml</exclude>??
  8. ????????????</excludes>??????????????<outputDirectory>\</outputDirectory>??
  9. ????????</fileSet>??????</fileSets>??
  10. ??????????<dependencySets>??
  11. ????????<dependencySet>??????????????<useProjectArtifact>true</useProjectArtifact>??
  12. ????????????<outputDirectory>lib</outputDirectory><!--?将scope为runtime的依赖包打包到lib目录下。?-->??????????????<scope>runtime</scope>??
  13. ????????</dependencySet>??????</dependencySets>??
  14. </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>

读书人网 >编程

热点推荐