你是否想要创建一个包含脚本、配置文件以及所有运行时所依赖的元素(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 文件里面的配置说明

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

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

  1. <assembly
  2. xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
  5. <id>release</id>
  6. <formats>
  7. <format>zip</format>
  8. </formats>
  9. <fileSets>
  10. <fileSet>
  11. <directory>${project.basedir}\src\main\config</directory>
  12. <!-- 过滤 -->
  13. <excludes>
  14. <exclude>*.xml</exclude>
  15. </excludes>
  16. <outputDirectory>\</outputDirectory>
  17. </fileSet>
  18. </fileSets>
  19. <dependencySets>
  20. <dependencySet>
  21. <useProjectArtifact>true</useProjectArtifact>
  22. <outputDirectory>lib</outputDirectory><!-- 将scope为runtime的依赖包打包到lib目录下。 -->
  23. <scope>runtime</scope>
  24. </dependencySet>
  25. </dependencySets>
  26. </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 文件里面的配置说明

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

例:

  1. <span style="white-space:pre">            </span><plugin>
  2. <artifactId>maven-assembly-plugin</artifactId>
  3. <configuration>
  4. <!-- not append assembly id in release file name -->
  5. <appendAssemblyId>false</appendAssemblyId>
  6. <descriptors>
  7. <descriptor>src/main/assembly/assembly.xml</descriptor>
  8. </descriptors>
  9. </configuration>
  10. <executions>
  11. <execution>
  12. <id>make-assembly</id>
  13. <phase>package</phase>
  14. <goals>
  15. <goal>single</goal>
  16. </goals>
  17. </execution>
  18. </executions>
  19. </plugin>

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

  1. <assembly
  2. xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
  5. <id>release</id>
  6. <formats>
  7. <format>zip</format>
  8. </formats>
  9. <fileSets>
  10. <fileSet>
  11. <directory>${project.basedir}\src\main\config</directory>
  12. <!-- 过滤 -->
  13. <excludes>
  14. <exclude>*.xml</exclude>
  15. </excludes>
  16. <outputDirectory>\</outputDirectory>
  17. </fileSet>
  18. </fileSets>
  19. <dependencySets>
  20. <dependencySet>
  21. <useProjectArtifact>true</useProjectArtifact>
  22. <outputDirectory>lib</outputDirectory><!-- 将scope为runtime的依赖包打包到lib目录下。 -->
  23. <scope>runtime</scope>
  24. </dependencySet>
  25. </dependencySets>
  26. </assembly>

例:

    1. <assembly>
    2. <id>assembly</id>
    3. <formats>
    4. <format>tar.gz</format>
    5. </formats>
    6. <includeBaseDirectory>true</includeBaseDirectory>
    7. <fileSets>
    8. <fileSet>
    9. <directory>${project.build.directory}/resources</directory>
    10. <outputDirectory>resources</outputDirectory>
    11. <fileMode>0755</fileMode>
    12. </fileSet>
    13. <fileSet>
    14. <directory>${project.build.directory}/config</directory>
    15. <outputDirectory>config</outputDirectory>
    16. <fileMode>0644</fileMode>
    17. </fileSet>
    18. <fileSet>
    19. <directory>${project.build.directory}/bin</directory>
    20. <outputDirectory>bin</outputDirectory>
    21. <fileMode>0755</fileMode>
    22. </fileSet>
    23. </fileSets>
    24. <dependencySets>
    25. <dependencySet>
    26. <outputDirectory>lib</outputDirectory>
    27. </dependencySet>
    28. </dependencySets>
    29. </assembly>

maven assembly 配置详解的更多相关文章

  1. mybatis 代码生成器(IDEA, Maven)及配置详解(部分配置你应该不知道)

    目录 1 创建代码生成器 1.1 创建Maven项目 1.2 配置 generator.xml 1.3 配置 pom.xml 1.4 使用及测试 2 XML 配置详解 2.1 优先 2.2 官网没有的 ...

  2. maven环境配置详解,及maven项目的搭建及maven项目聚合

    首先:Maven 3.2.1:不同版本中仓库中文件是不一样的,Maven运行,先找用户配置,再找全局配置 1. Maven全局配置:全局统一的配置文件,在maven的安装目录中 2. Maven用户配 ...

  3. maven常用插件配置详解

    常用插件配置详解Java代码    <!-- 全局属性配置 --> <properties> <project.build.name>tools</proje ...

  4. Maven 变量及常见插件配置详解

    Maven 的 pom.xml 常用 变量 插件 配置 详解 一.变量 - 自定义变量及内置变量 1. 自定义变量 <properties> <project.build.name& ...

  5. Maven使用笔记(四)pom.xml配置详解

    pom.xml文件配置详解 --声明规范 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=" ...

  6. 【转】Maven pom.xml 配置详解

    原文链接:https://yq.aliyun.com/articles/38271 pom.xml文件配置详解 --声明规范 <project xmlns="http://maven. ...

  7. maven配置详解

    什么是pom?     pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述了项目:包括配置文件:开发者需要遵循的规则,缺陷管理系统,组织和licenses,项目的 ...

  8. (转)Maven pom.xml 配置详解

    背景:maven一直感觉既熟悉又陌生,归根结底还是自己不太熟. 1 什么是pom? pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述了项目:包括配置文件:开发者 ...

  9. maven pom文件简单模板和配置详解

    https://blog.csdn.net/earbao/article/details/49924943 maven pom文件简单模板和配置详解

随机推荐

  1. CentOS7环境下SSH端口修改笔记

    CentOS7环境下SSH端口修改笔记 说明: CentOS7服务器环境,默认SSH端口为22,考虑到安全方面问题,欲修改端口为62231(机器内网IP为192.168.1.31) ssh配置文件和i ...

  2. zabbix日志监控

    一般情况下,日志最先反映出应用当前的问题,在海量日志里面找到我们异常记录,例如监控系统日志.nginx.Apache.业务日志,然后记录下来,并且根据情况报警. 1.日志监控项介绍 最主要的是监控日志 ...

  3. 通过脚本发送zabbix邮件报警

    zabbix原生的报警媒介类型中,邮件报警是我们常用的方式.当我们在CentOS6上面安装zabbix3.0并配置邮件报警的时候,在邮件配置正确的前提下,不管触发器如何触发,邮件总是发送不出去,但是在 ...

  4. spring 配置多数据源 (可行)

    可以看到AbstractRoutingDataSource获取数据源之前会先调用determineCurrentLookupKey方法查找当前的lookupKey,这个lookupKey就是数据源标识 ...

  5. 用Fiddler或Charles进行mock数据搭建测试环境

    转载:http://blog.csdn.net/qqYJ5/article/details/62216582 应用场景:服务器数据不符合测试条件或者服务器未开发完成时,我们可以通过在本地创建数据来达到 ...

  6. Mysql和SqlServer互相转换

    环境: Windows XP sp2 MS SQL Server 2OOO sp1 MySql 5.0.41 1:MSSQLServer数据库导入到MySql数据库 步骤: 1.安装mysql数据库的 ...

  7. close_wait状态的产生原因及解决(转)

    最近测试环境server由于需要与大量的后台server交互,今天突然发现有大量的close_wait产生,于是仔细研究了一下: 如果我们的服务器程序处于CLOSE_WAIT状态的话,说明套接字是被动 ...

  8. P-Called-Party-ID 头域的应用说明

    P-Called-Party-ID 头域的适用场景 P-Called-Party-ID 适用于 UAS 须要知道在代理将目标改写为Contact 地址之前请求中Request-URI的目的AOR的情况 ...

  9. 数据访问公共类(BaseProvider)

    using System; using System.Data; using System.Data.Common; using System.Configuration; using System. ...

  10. 解决:cant&#39;t run &#39;/etc/init.d/rcS&#39;:No such file or directory

    Linux内核启动时提示这种错误:cant't run '/etc/init.d/rcS':No such file or directory 请用vim打开文件:/etc/init.d/rcS 观察 ...