maven-assembly-plugin入门
愿文地址:https://www.jianshu.com/p/e8585a991e8e
当你使用 Maven 对项目打包时,你需要了解以下 3 个打包 plugin,它们分别是
| plugin | function |
|---|---|
| maven-jar-plugin | maven 默认打包插件,用来创建 project jar |
| maven-shade-plugin | 用来打可执行包,executable(fat) jar |
| maven-assembly-plugin | 支持定制化打包方式,例如 apache 项目的打包方式 |
下面我们就简单介绍一下 maven-assembly-plugin。
使用方法
- 使用 descriptorRefs(官方提供的定制化打包方式),官方提供的 descriptorRef 有 bin, jar-with-dependencies, src, project。【不建议使用】
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<!-- NOTE: We don't need a groupId specification because the group is
org.apache.maven.plugins ...which is assumed by default.
-->
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
[...]
</project>
- 使用 descriptors,指定打包文件 src/assembly/src.xml,在该配置文件内指定打包操作。
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptors>
<descriptor>src/assembly/src.xml</descriptor>
</descriptors>
</configuration>
[...]
</project>
描述符文件元素
id
<id>release</id>
id 标识符,添加到生成文件名称的后缀符。如果指定 id 的话,目标文件则是 ${artifactId}-${id}.tar.gz
formats
maven-assembly-plugin 支持的打包格式有zip、tar、tar.gz (or tgz)、tar.bz2 (or tbz2)、jar、dir、war,可以同时指定多个打包格式
<formats>
<format>tar.gz</format>
<format>dir</format>
</formats>
dependencySets
用来定制工程依赖 jar 包的打包方式,核心元素如下表所示。
| 元素 | 类型 | 作用 |
|---|---|---|
| outputDirectory | String | 指定包依赖目录,该目录是相对于根目录 |
| includes/include* | List<String> | 包含依赖 |
| excludes/exclude* | List<String> | 排除依赖 |
<dependencySets>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
</dependencySet>
</dependencySets>
fileSets
管理一组文件的存放位置,核心元素如下表所示。
| 元素 | 类型 | 作用 |
|---|---|---|
| outputDirectory | String | 指定文件集合的输出目录,该目录是相对于根目录 |
| includes/include* | List<String> | 包含文件 |
| excludes/exclude* | List<String> | 排除文件 |
| fileMode | String | 指定文件属性,使用八进制表达,分别为(User)(Group)(Other)所属属性,默认为 0644 |
<fileSets>
<fileSet>
<includes>
<include>bin/**</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<includes>
<include>/conf/**</include>
<include>logs</include>
</includes>
</fileSet>
</fileSets>
files
可以指定目的文件名到指定目录,其他和 fileSets 相同,核心元素如下表所示。
| 元素 | 类型 | 作用 |
|---|---|---|
| source | String | 源文件,相对路径或绝对路径 |
| outputDirectory | String | 输出目录 |
| destName | String | 目标文件名 |
| fileMode | String | 设置文件 UNIX 属性 |
<files>
<file>
<source>README.txt</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
样例
工程目录结构

pom.xml
<build>
<finalName>scribe-log4j2-test</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/release.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
release.xml
<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">
<formats>
<format>tar.gz</format>
<format>dir</format>
</formats>
<dependencySets>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<includes>
<include>bin/**</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<includes>
<include>/conf/**</include>
<include>logs</include>
</includes>
</fileSet>
</fileSets>
<files>
<file>
<source>README.txt</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
</assembly>
最终创建生成可执行二进制工程
参考
maven 入门指南
maven 生命周期
Maven 默认插件以及功能
maven 依赖管理
maven-shade-plugin 入门指南
maven-assembly-plugin
maven-assembly-plugin入门的更多相关文章
- 记录一次maven打包时将test目录下的类打包到jar中,Maven Assembly Plugin的使用
今天有人问我打包后找不到主类,运行的类写在test中.按照常规,test目录下的文件不会打包到jar包中.(但是我测试一个springboot工程就可以,这里之后再研究) 具体解决如下 第一步:在po ...
- maven assembly plugin使用
使用场景 在使用maven来管理项目时,项目除了web项目,还有可能为控制台程序,一般用于开发一些后台服务的程序.最近在工作中也遇到了这种场景,使用quartz开发一个任务调度程序.程序中依赖很多ja ...
- 使用Maven Assembly plugin将依赖打包进jar
一个Eclipse的工程,在pom中配置了若干依赖,需要将pom中所有的依赖全部打包进一个jar包中,可以选择的方案有maven-assembly-plugin和fatjar.以前采用fatjar进行 ...
- Maven Assembly插件介绍
转自:http://blueram.iteye.com/blog/1684070 已经写得挺好的,就不用重写了. 你是否想要创建一个包含脚本.配置文件以及所有运行时所依赖的元素(jar)Assembl ...
- maven assembly 配置详解
Maven Assembly插件介绍 博客分类: 项目构建 你是否想要创建一个包含脚本.配置文件以及所有运行时所依赖的元素(jar)Assembly插件能帮你构建一个完整的发布包. Assembl ...
- 学习Maven之Maven Enforcer Plugin
1.Maven Enforcer plugin是什么鬼? 在说这个插件是什么前我们先思考这么一个问题:当我们开发人员进入项目组进行开发前,要准备开发环境,而领导总是会强调工具的统一,编译环境的统一.比 ...
- [Maven] - Eclipse "maven compiler plugin" 冲突解决
刚安装最新的Maven 3.2.5,在eclipse中使用maven的Run As->Maven Install,总会提示: Failed to execute goal org.apache. ...
- [Apache Maven Shade Plugin] [example] [001] 官方例子:includes-excludes
链接地址:[Selecting Contents for Uber JAR](http://maven.apache.org/plugins/maven-shade-plugin/examples/i ...
- maven jetty plugin
转载:http://blog.163.com/xueling1231989@126/blog/static/1026408072013101311395492/ 前言: 在 maven 下测试调试时, ...
- 施用 maven shade plugin 解决 jar 或类的多版本冲突
施用 maven shade plugin 解决 jar 或类的多版本冲突 使用 maven shade plugin 解决 jar 或类的多版本冲突java 应用经常会碰到的依赖的三方库出现版本 ...
随机推荐
- 原 Linux:ping不通baidu.com
如果某台Linux服务器ping不通域名, 如下提示: [root@localhost ~]# ping www.baidu.com ping: unknown host www.baidu.com ...
- JS异步解决方案
前言 异步最早的解决方案是回调函数,如ajax,事件的回调,setInterval/setTimeout中的回调.但是回调函数有回调地狱的问题; 为了解决回调地狱的问题,社区提出了Promise解决方 ...
- FreeSql配合仓储实现软删除
该篇内容由个人博客点击跳转同步更新!转载请注明出处! 前段时间使用FreeSql作为ORM,写了一个简单的CMS,在这里总结一下其中的使用心得. 仓储配合全局过滤器 1. 统一的删除标志 如:数据库字 ...
- C. 【UNR #3】配对树
题解: 首先可以贪心 于是问题可以等价成一条边被算当且仅当子树中个数为奇数个 题解的做法比较简单 考虑每条边,加入其子树内的点 然后为了保证区间长度为偶数 分成f0,0 f0,1 f1,0 f1,1即 ...
- SSI(服务器端嵌入)
简介 SSI(服务器端嵌入)是一组放在 HTML 页面中的指令,当服务器向客户端访问提供这些页面时,会解释执行这些指令.它们能为已有的 HTML 页面添加动态生成内容,不需要通过 CGI 程序来或其他 ...
- STM32 命名方法
1.STM32型号的说明:以STM32F103RBT6这个型号的芯片为例,该型号的组成为7个部分,其命名规则如下: STM32 ST公司生产的Cortex-M内核的32位微控制器 F F代表产品类型 ...
- python中交换两个变量值的方法
a = 4b = 5 #第1种c = 0c = aa = bb = c #第2种a = a+bb = a-ba = a-b #第3种a,b = b,a print("a=%d,b=%d&qu ...
- TypeScript躬行记(7)——命名空间
TypeScript中的命名空间可将那些具有内在联系的接口.类或对象等代码组织在一起,既能隔离作用域,也能避免命名冲突,并且使得代码结构清晰,更易追踪.在命名空间内部,所有实体部分默认都是私有的,需要 ...
- 利用selenium库自动执行滑动验证码模拟登陆
破解流程 #1.输入账号.密码,然后点击登陆 #2.点击按钮,弹出没有缺口的图 #3.针对没有缺口的图片进行截图 #4.点击滑动按钮,弹出有缺口的图 #5.针对有缺口的图片进行截图 #6.对比两张图片 ...
- Docker+Nginx使用流程(笔记)
Docker+Nginx使用流程 本教程依据个人理解并经过实际验证为正确,特此记录下来,权当笔记. 注:基于linux操作系统 # uname -r 查看你当前的内核版本 # yum -y insta ...