Maven常用插件介绍:Maven-assembly-plugin插件
2016-06-20 10:54
375 查看
一:插件的作用
Maven-assembly-plugin插件作用:要想将写的程序和它本身所依赖的jar包一起build到一个包里,是maven中针对打包任务而提供的标准插件。
其他的功能:
1. 提供一个把工程依赖元素、模块、网站文档等其他文件存放到单个归档文件里。
2. 打包成指定格式分发包,支持各种主流的格式如zip、tar.gz、jar和war等,具体打包哪些文件是高度可控的。
3. 能够自定义包含/排除指定的目录或文件。
二:使用步骤:
1.
需要指定一个Assembly描述符文件,该文件指定了打包格式,包含的文件/过滤的文件等信息,可以同时指定多个描述符文件,打包成不同的格式;
2. 工程的pom.xml里配置Assembly插件。
三:案例介绍
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<id>${project.version}</id><!--名字任意
-->
<phase>package</phase> <!--
绑定到package生命周期阶段上 -->
<goals>
<goal>single</goal> <!--
只运行一次 -->
</goals>
<configuration>
<descriptors> <!--描述文件路径-->
<descriptor>dist.xml</descriptor>
</descriptors>
<!--这样配置后,mvn deploy不会把assembly打的zip包上传到nexus-->
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>
Dist.xml文件描述:
<assemblyxmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <id>dist</id>
<formats><!--打包的文件格式
-->
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>src/main/bin</directory><!--需要打包的目录
-->
<outputDirectory>/bin</outputDirectory> <!--
打包后输出的路径 -->
</fileSet>
<fileSet>
<directory>src/main/conf</directory>
<outputDirectory>/conf</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact><!-- 当前项目构件是否包含在这个依赖集合里
-->
<outputDirectory>lib</outputDirectory><!--将scope为runtime的依赖包打包到lib目录下。
-->
</dependencySet>
</dependencySets>
</assembly>
Maven-assembly-plugin插件作用:要想将写的程序和它本身所依赖的jar包一起build到一个包里,是maven中针对打包任务而提供的标准插件。
其他的功能:
1. 提供一个把工程依赖元素、模块、网站文档等其他文件存放到单个归档文件里。
2. 打包成指定格式分发包,支持各种主流的格式如zip、tar.gz、jar和war等,具体打包哪些文件是高度可控的。
3. 能够自定义包含/排除指定的目录或文件。
二:使用步骤:
1.
需要指定一个Assembly描述符文件,该文件指定了打包格式,包含的文件/过滤的文件等信息,可以同时指定多个描述符文件,打包成不同的格式;
2. 工程的pom.xml里配置Assembly插件。
三:案例介绍
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<id>${project.version}</id><!--名字任意
-->
<phase>package</phase> <!--
绑定到package生命周期阶段上 -->
<goals>
<goal>single</goal> <!--
只运行一次 -->
</goals>
<configuration>
<descriptors> <!--描述文件路径-->
<descriptor>dist.xml</descriptor>
</descriptors>
<!--这样配置后,mvn deploy不会把assembly打的zip包上传到nexus-->
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>
Dist.xml文件描述:
<assemblyxmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <id>dist</id>
<formats><!--打包的文件格式
-->
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>src/main/bin</directory><!--需要打包的目录
-->
<outputDirectory>/bin</outputDirectory> <!--
打包后输出的路径 -->
</fileSet>
<fileSet>
<directory>src/main/conf</directory>
<outputDirectory>/conf</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact><!-- 当前项目构件是否包含在这个依赖集合里
-->
<outputDirectory>lib</outputDirectory><!--将scope为runtime的依赖包打包到lib目录下。
-->
</dependencySet>
</dependencySets>
</assembly>
相关文章推荐
- cocoaPods详细操作
- 1 Lucene笔记(一):创建索引库、根据关键字搜索
- 网络游戏同步问题
- 改了计算机名后,sqlserver进行发布订阅时,提示此实例上未安装复制组件
- Java关键字final、static使用总结
- Centos 7 (linux)部署MongoDB
- Android中补间动画的基本使用
- ios swift例子源码网址总结
- code1225 搭积木
- android线程操作类(暂停、重新开启、停止)
- ios swift例子源码网址总结
- 【FOL】第二周
- 通用经验:大企业如何逆势而上
- js时间字符串转时间戳
- 探寻C++最快的读取文件的方案
- STL源码剖析——stl_algobase.h
- struts2的文件上传与下载
- go语言学习之路 二:变量
- 福耀经验:如何把利润做到最大化
- java线程和进程