maven assembly 配置详解
你是否想要创建一个包含脚本、配置文件以及所有运行时所依赖的元素(jar)Assembly插件能帮你构建一个完整的发布包。
Assembly插件会生成 “assemblies”, 此特性等同于的Maven 1 distribution plug-in.。该插件不仅支持创建二进制归档文件,也支持创建源码归档文件。这些assemblies定义在一个assembly描述符文件里。你可以选择自定义assembly描述符或者直接使用插件自带的三个预定义描述符中的任何一个.
目前Assembly插件支持如下格式的归档文件:
- zip
- tar.gz
- tar.bz2
- jar
- dir
- war
- and any other format that the ArchiveManager has been configured for
Maven 2上使用assembly的简单步骤:
- 从预定义描述符里选择一个或者自己编写一个assembly描述符号。
- 工程的pom.xml里配置Assembly插件。
- 在工程根目录下运行”mvn assembly:assembly”命令 。
如何自定义assembly描述符,详见Assembly Descriptor Format.
什么是Assembly?
“assembly”是把一组文件、目录、依赖元素组装成一个归档文件. 比如, 假设一个 Maven project定义了一个JAR artifact,它包含控制台应用程序和Swing应用程序 。这样一个工程可以定义两套包含描述符,一套给给控制台应用,另一套给Swing应用程序,它们包含各自的脚本、目录和依赖。
Assembly Plugin的描述符可以定义任何一个文件或者目录归档方式。举个例子,如果的你的Maven 2工程包含”src/main/bin”这个目录,你可以指示Assembly插件复制“src/main/bin”目录下所有的文件到bin目录里(归档文件里的目录),并且可以修改它们的权限属性(UNIX mode)。见 assembly descriptor.
The Maven Assembly Plugin
Maven 2.0的Assembly插件目的是提供一个把工程依赖元素、模块、网站文档等其他文件存放到单个归档文件里。
使用任何一个预定义的描述符你可以轻松的构建一个发布包。这些描述符能处理一些常用的操作,如:把依赖的元素的归档到一个jar文件. 当然, 你可以自定义描述符来更灵活的控制依赖,模块,文件的归档方式。
maven-assembly-plugin : 是maven中针对打包任务而提供的标准插件
(1)、在pom.xml 文件里面的配置说明
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <executions> <!--执行器 mvn assembly:assembly-->
- <execution>
- <id>make-zip</id><!--名字任意 -->
- <phase>package</phase><!-- 绑定到package生命周期阶段上 -->
- <goals>
- <goal>single</goal><!-- 只运行一次 -->
- </goals>
- <configuration>
- <descriptors> <!--描述文件路径-->
- <descriptor>src/main/resources/zip.xml</descriptor>
- </descriptors>
- </configuration>
- </execution>
- </executions>
- </plugin>
(2)、zip.xml 文件配置如下
- <assembly
- xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
- 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">
- <id>release</id>
- <formats>
- <format>zip</format>
- </formats>
- <fileSets>
- <fileSet>
- <directory>${project.basedir}\src\main\config</directory>
- <!-- 过滤 -->
- <excludes>
- <exclude>*.xml</exclude>
- </excludes>
- <outputDirectory>\</outputDirectory>
- </fileSet>
- </fileSets>
- <dependencySets>
- <dependencySet>
- <useProjectArtifact>true</useProjectArtifact>
- <outputDirectory>lib</outputDirectory><!-- 将scope为runtime的依赖包打包到lib目录下。 -->
- <scope>runtime</scope>
- </dependencySet>
- </dependencySets>
- </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>
另一个讲解:
(1)、在pom.xml 文件里面的配置说明
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <executions> <!--执行器 mvn assembly:assembly-->
- <execution>
- <id>make-zip</id><!--名字任意 -->
- <phase>package</phase><!-- 绑定到package生命周期阶段上 -->
- <goals>
- <goal>single</goal><!-- 只运行一次 -->
- </goals>
- <configuration>
- <descriptors> <!--描述文件路径-->
- <descriptor>src/main/resources/zip.xml</descriptor>
- </descriptors>
- </configuration>
- </execution>
- </executions>
- </plugin>
例:
- <span style="white-space:pre"> </span><plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <configuration>
- <!-- not append assembly id in release file name -->
- <appendAssemblyId>false</appendAssemblyId>
- <descriptors>
- <descriptor>src/main/assembly/assembly.xml</descriptor>
- </descriptors>
- </configuration>
- <executions>
- <execution>
- <id>make-assembly</id>
- <phase>package</phase>
- <goals>
- <goal>single</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
(2)、zip.xml 文件配置如下
- <assembly
- xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
- 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">
- <id>release</id>
- <formats>
- <format>zip</format>
- </formats>
- <fileSets>
- <fileSet>
- <directory>${project.basedir}\src\main\config</directory>
- <!-- 过滤 -->
- <excludes>
- <exclude>*.xml</exclude>
- </excludes>
- <outputDirectory>\</outputDirectory>
- </fileSet>
- </fileSets>
- <dependencySets>
- <dependencySet>
- <useProjectArtifact>true</useProjectArtifact>
- <outputDirectory>lib</outputDirectory><!-- 将scope为runtime的依赖包打包到lib目录下。 -->
- <scope>runtime</scope>
- </dependencySet>
- </dependencySets>
- </assembly>
例:
- <assembly>
- <id>assembly</id>
- <formats>
- <format>tar.gz</format>
- </formats>
- <includeBaseDirectory>true</includeBaseDirectory>
- <fileSets>
- <fileSet>
- <directory>${project.build.directory}/resources</directory>
- <outputDirectory>resources</outputDirectory>
- <fileMode>0755</fileMode>
- </fileSet>
- <fileSet>
- <directory>${project.build.directory}/config</directory>
- <outputDirectory>config</outputDirectory>
- <fileMode>0644</fileMode>
- </fileSet>
- <fileSet>
- <directory>${project.build.directory}/bin</directory>
- <outputDirectory>bin</outputDirectory>
- <fileMode>0755</fileMode>
- </fileSet>
- </fileSets>
- <dependencySets>
- <dependencySet>
- <outputDirectory>lib</outputDirectory>
- </dependencySet>
- </dependencySets>
- </assembly>
maven assembly 配置详解的更多相关文章
- mybatis 代码生成器(IDEA, Maven)及配置详解(部分配置你应该不知道)
目录 1 创建代码生成器 1.1 创建Maven项目 1.2 配置 generator.xml 1.3 配置 pom.xml 1.4 使用及测试 2 XML 配置详解 2.1 优先 2.2 官网没有的 ...
- maven环境配置详解,及maven项目的搭建及maven项目聚合
首先:Maven 3.2.1:不同版本中仓库中文件是不一样的,Maven运行,先找用户配置,再找全局配置 1. Maven全局配置:全局统一的配置文件,在maven的安装目录中 2. Maven用户配 ...
- maven常用插件配置详解
常用插件配置详解Java代码 <!-- 全局属性配置 --> <properties> <project.build.name>tools</proje ...
- Maven 变量及常见插件配置详解
Maven 的 pom.xml 常用 变量 插件 配置 详解 一.变量 - 自定义变量及内置变量 1. 自定义变量 <properties> <project.build.name& ...
- Maven使用笔记(四)pom.xml配置详解
pom.xml文件配置详解 --声明规范 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=" ...
- 【转】Maven pom.xml 配置详解
原文链接:https://yq.aliyun.com/articles/38271 pom.xml文件配置详解 --声明规范 <project xmlns="http://maven. ...
- maven配置详解
什么是pom? pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述了项目:包括配置文件:开发者需要遵循的规则,缺陷管理系统,组织和licenses,项目的 ...
- (转)Maven pom.xml 配置详解
背景:maven一直感觉既熟悉又陌生,归根结底还是自己不太熟. 1 什么是pom? pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述了项目:包括配置文件:开发者 ...
- maven pom文件简单模板和配置详解
https://blog.csdn.net/earbao/article/details/49924943 maven pom文件简单模板和配置详解
随机推荐
- mapbox 接入高德矢量地图实战
Mapbox 作为现如今比较流行的地图框架为我们提供了漂亮的个性化地图,在平常的使用过程中可以方便的接入高德/谷歌等矢量切片地图.由于Mapbox地图数据来源于Open Street Map等国外厂商 ...
- ElasticSearch测试数据
curl命令数据 curl -XPUT http://127.0.0.1:9200/us/user/1 -d "{\"email\":\"john@smith. ...
- 2017.4.7 e.toString() 与 e.getMessage()的区别
我使用的时候,抛出了空指针异常,本来是想将异常信息显示在errorInfo里,却发现没有拿到错误信息. 原因:我用的是getMessage(). 用e.getMessage() 时,返回的是null. ...
- 通过项目了解JAVA注解
java自定义注解实践 ² 背景 最近在为公司的技术改造做准备,我设计了一个提高Web开发效率的技术框架,为了增加框架的友好性和易用性,决定采用注解来代替配置文件,于是我查询了很多的资料,进行整理和学 ...
- SQLite升级数据库:
SQLiteOpenHelper子类关键代码: SQLite升级数据库: SQLiteOpenHelper子类关键代码: public class MyDataHelper extends SQLit ...
- mongo 增
mongodb存储的是文档,文档是json格式的对象,我们的增删改查,都要传输json对象 json是一个对象,js里有数组这个概念,只需要把多个对象放到一个数组里,即可 use test //首先选 ...
- 【Lucene】Apache Lucene全文检索引擎架构之入门实战1
Lucene是一套用于全文检索和搜寻的开源程式库,由Apache软件基金会支持和提供.Lucene提供了一个简单却强大的应用程式接口,能够做全文索引和搜寻.在Java开发环境里Lucene是一个成熟的 ...
- maven初始搭建一个基础项目(spring mvc+spring+jdbc mysql+jstl)
技术选型: 一.项目搭建: 1)创建maven项目 (我博客里面有介绍) 选择aptach的maven-archetype-webapp 填入groupIDhe artifactId等 确认项目名称 ...
- Android Studio 2.0 正式版公布啦 (首次中文翻译)
Android Studio 2.0 公布了,添加了一些新特性: 1. 更加完好的 Instant Run 2. 更快的 Android Emulator 3.GPU Debugger Preview ...
- EasyNetQ操作RabbitMQ(高级消息队列)
RabbitMQ是实现了高级消息队列协议(AMQP)的开源消息代理软件(亦称面向消息的中间件).写消息队列的时候用RabbitMQ比较好,但是写的时候需要自己封装下,自己的封装,就需要对RabbitM ...