pom文件中maven-assembly-plugin插件学习
来源:互联网 发布:为什么淘宝电脑便宜 编辑:程序博客网 时间:2024/05/17 01:22
身为码农的我,最近开发项目,用的是maven管理项目,在pom.xml文件里有一项配置:maven-assembly-plugin,不太清楚是做什么的,所以学习了一下,现整理记录如下:
一、使用场景
如果项目是微服务架构,可能用到这个插件的概率比较高,平时普通的项目不需要这样的实现方式。
如果项目内的一部分通用功能,不需要挨个引用,则需要将通用功能部分达成jar包。
二、Maven-assembly-plugin作用
1、作用:要想将写的程序和它本身所依赖的jar包一起build到一个包里,是maven中针对打包任务而提供的标准插件。
2、其他作用:
1)提供一个把工程依赖元素、模块、网站文档等其他文件存放到单个归档文件里。
2)打包成指定格式分发包,支持各种主流的格式如zip、tar.gz、jar和war等,具体打包哪些文件是高度可控的。
3)能够自定义包含/排除指定的目录或文件。
三、总体来说,实现插件maven-assembly-plugin需要两个步骤:
第1步骤:pom.xml文件里配置maven-assembly-plugin,指定描述文件
第2步骤:描述文件配置具体参数
对应步骤1 ------> 项目中pom.xml的配置如下:
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.study</groupId><artifactId>center</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><build><plugins><plugin><artifactId>maven-assembly-plugin</artifactId><configuration><appendAssemblyId>false</appendAssemblyId><descriptors><descriptor>src/main/assembly/package.xml</descriptor></descriptors></configuration><executions><execution><id>make-assembly</id><phase>package</phase><goals><goal>single</goal></goals></execution></executions></plugin></plugins></build></project>单行解释如下:
<plugin> <artifactId>maven-assembly-plugin</artifactId> <!--插件引用--> <configuration> <appendAssemblyId>false</appendAssemblyId> <descriptors> <!--描述文件路径-->
<descriptor>src/main/assembly/package.xml</descriptor>
</descriptors>
</configuration> <executions> <execution> <id>make-assembly</id> <!--名字任意 --> <phase>package</phase> <!-- 绑定到package生命周期阶段上 --> <goals> <goal>single</goal> <!-- 只运行一次 --> </goals> </execution> </executions></plugin>
对应步骤2 ------> 这样配置后,在项目的对应路径下,找到package.xml文件(描述文件)
package.xml文件(描述文件)内容如下:
<?xml version="1.0" encoding="UTF-8"?><assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> <id>package</id> <formats> <format>dir</format> </formats> <includeBaseDirectory>true</includeBaseDirectory> <fileSets> <fileSet> <directory>src/main/resources</directory> <outputDirectory>/config</outputDirectory> </fileSet> <fileSet> <directory>src/main/bin</directory> <outputDirectory>/</outputDirectory> </fileSet> <fileSet> <directory>${project.build.directory}</directory> <outputDirectory>/</outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> </fileSets> <dependencySets> <dependencySet> <outputDirectory>lib</outputDirectory> <scope>runtime</scope> <excludes> <exclude>${groupId}:${artifactId}</exclude> </excludes> </dependencySet> </dependencySets></assembly>
描述符文件说明:
1、ID
id 标识符,添加到生成文件名称的后缀符。如果指定 id 的话,目标文件则是 ${artifactId}-${id}.tar.gz
<id>package</id>
2、formats
maven-assembly-plugin 支持的打包格式有zip、tar、tar.gz (or tgz)、tar.bz2 (or tbz2)、jar、dir、war,可以同时指定多个打包格式
<formats> <format>dir</format>
...可配置多个</formats>
3、dependencySets
用来定制工程依赖 jar 包的打包方式,核心元素如下:
String
指定包依赖目录,该目录是相对于根目录
includes/include*
List<String>包含依赖
excludes/exclude*
List<String>排除依赖
<dependencySets> <dependencySet> <outputDirectory>lib</outputDirectory> <scope>runtime</scope> <excludes> <exclude>${groupId}:${artifactId}</exclude> </excludes> </dependencySet></dependencySets>
4、fileSets
管理一组文件的存放位置,核心元素如下:
元素类型作用outputDirectory
String
指定包依赖目录,该目录是相对于根目录
includes/include*
List<String>包含依赖
excludes/exclude*
List<String>排除依赖
<fileSets> <fileSet> <directory>src/main/resources</directory> <outputDirectory>/config</outputDirectory><!--resource文件输出路径--> </fileSet> <fileSet> <directory>src/main/bin</directory> <outputDirectory>/</outputDirectory> <!--bin目录文件输出路径-->
</fileSet> <fileSet> <directory>${project.build.directory}</directory> <!--jar文件输出路径--> <outputDirectory>/</outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet></fileSets>
三、找到生成的包
实现了上述两步之后,在项目路径/target目录下,有jar包如下:
打开center-0.0.1-SNAPSHOT文件,输出格式符合描述文件内的配置。如下:
- pom文件中maven-assembly-plugin插件学习
- Maven-assembly-plugin插件
- Maven学习之插件—maven-assembly-plugin
- Maven插件之maven-assembly-plugin
- pom.xml中maven-compiler-plugin插件配置的使用
- maven-assembly-plugin打包插件配置
- Maven学习总结(27)——Maven自定义打包插件maven-assembly-plugin详解
- 【Maven学习】maven-assembly-plugin的使用
- Maven常用插件介绍:Maven-assembly-plugin插件
- maven:maven-assembly-plugin
- maven 中pom.xml文件标签学习
- maven插件不执行-build-helper-maven-plugin pom中不执行
- Maven的打包插件maven-assembly-plugin介绍
- maven 自定义打包插件maven-assembly-plugin不完全记录
- maven java项目打包发布插件 maven-assembly-plugin
- 使用maven的maven-assembly-plugin将jar包依赖打包到一个jar文件中
- Project ID: org.apache.maven.plugins:maven-assembly-plugin Reason: POM 'org.apache.maven.plugins:ma
- maven assembly plugin使用
- ubuntu 下载速度太慢
- 关键字 标识符 注释 常量和变量 运算符
- 获取app中的资源文件:反编译APK之---------apktool
- 深入理解Java虚拟机:JVM高级特性与最佳实践 第2版
- jspf和jsp的区别
- pom文件中maven-assembly-plugin插件学习
- test
- 用OGNL表达式取值栈中的值
- 【安全牛学习笔记】HTTPS攻击
- 27. Remove Element 删除指定元素
- TCP/IP协议中的三次握手和四次分手
- 基于RMAN实现坏块介质恢复(block recover)
- 自顶向下,逐步求精
- double取小数点后一位