`
zhaohaolin
  • 浏览: 984115 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Maven assembly实现自定义打包(转)

 
阅读更多

maven-assembly-plugin : 是maven中针对打包任务而提供的标准插件

(1)、在pom.xml 文件里面的配置说明

[html] view plain copy
  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 文件配置如下

[html] view plain copy
  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.       
  20.     < dependencySets >   
  21.         < dependencySet >   
  22.             < useProjectArtifact > true </ useProjectArtifact >   
  23.             < outputDirectory > lib </ outputDirectory > <!-- 将scope为runtime的依赖包打包到lib目录下。 -->   
  24.             < scope > runtime </ scope >   
  25.         </ dependencySet >   
  26.     </ dependencySets >   
  27. </ 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>

分享到:
评论

相关推荐

    Maven build插件之Maven-assembly-plugin自定义打包

    Maven-assembly-plugin是maven中针对打包任务而提供的标准插件,可以实现自定义打包。主要提供如下功能: ● 提供一个把工程依赖元素、模块、网站文档等其他文件存放到单个归档文件里。 ● 打包成指定格式分发包,...

    maven-assembly 自定义打包方式

    maven-assembly 自定义打包方式,可以将工程打包为tar或其他格式,里面保留着配置文件的目录

    使用Maven assembly打多个自定义包及War包简介

    NULL 博文链接:https://byx5185.iteye.com/blog/739822

    maven打成可运行jar包

    当前pom.xml中详细的记录了将maven项目打成可运行jar包的完整代码,使用maven的插件maven-assembly-plugin,同时将所有依赖打到jar包中,亲测可用。

    Maven权威指南 很精典的学习教程,比ANT更好用

    通过Maven Profiles实现可移植性 11.2.1. 覆盖一个项目对象模型 11.3. 激活Profile 11.3.1. 激活配置 11.3.2. 通过属性缺失激活 11.4. 外部Profile 11.5. Settings Profile 11.5.1. 全局Settings ...

    ca源码java-canal-assembly:canal[kə'næl],主要用途是用于MySQL数据库增量日志数据的订阅、消费和解析,是阿

    使用Maven的assembly插件实现自定义打包;可以实现 1、配置文件与源码分开 2、项目依赖的jar包放到指定位置,同时把项目本身打成jar包 部署操作: 1、需要修改logback-spring.xml文件中的日志存放位置 2、修改druid....

    spring-mvc-init:Spring项目 脚手架 spring 全家桶

    maven-assembly-plugin 自定义打包工具 maven-compiler-plugin 编译工具 脚手架特性 生产/开发环境切换 本地开发使用classpath下的jdbc.properties 测试环境使用env/config-dev/jdbc.properties 生产环境使用env/...

    custom-plugin-demo:自定义插件

    插件系统演示 该项目演示了如何使用 java 打包、maven 构建系统和运行时类加载构建基于插件的简单应用程序。 结构 这是一个多模块的maven项目 ... 转到plugin-app并运行mvn compile assembly:single后

    开源中国源码

    2. 程序部署建议使用Maven的assembly插件实现自定义打包方式 3. 项目已经接入了solr,程序安装需要先运行solr,solr已调试好,可直接启动,使用方法可访问官网查看; 4. 项目用到了阿里大于jar包,Maven时无法使用,...

    Test_Spring_Cloud_Compoint:使用Spring Cloud 集成集群以及其他的组件

    使用Spring Cloud 集成集群以及其他的组件 0 eureka 集群 1 根据项目的不同集成不同的组件 2 日志集成的是Logback 自定义的形式 3 集成 Swagger2 4 集成Spring-Security...5 使用Maven-assembly打包成zip包 6 未完 待续

    单点登录源码

    Maven | 项目构建管理 | [http://maven.apache.org/](http://maven.apache.org/) #### 前端技术: 技术 | 名称 | 官网 ----|------|---- jQuery | 函式库 | [http://jquery.com/](http://jquery.com/) Bootstrap | ...

Global site tag (gtag.js) - Google Analytics