maven学习(二)
为了兼容之前基于ant构建的项目发布包结构,在基于maven做构建的时候,需要自定义打包方式。
maven的maven-assembly-plugin插件支持任意格式的打包,比如:dir,zip等形式。项目的maven工程结构,如下所示:

(图一)
发布包结构如下所示:

(图二)
最初的想法是父模块等待子模块全部构建完成之后,将子模块构建后的jar全部拷贝到父模块的target的合适位置。但是,maven构建的时候优先构建父模块,子模块的构建依托其依赖关系决定。而且,父模块不能依赖子模块,否则导致循环依赖。因此,在子模块这一层添加一个distribution,专门负责自定义打包的处理,其依赖所有同一层的子模块。
kernel-distribution中maven-assembly-plugin的定义:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
其assembly.xml的定义:
<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>kernel</id>
<formats>
<format>dir</format>
</formats>
<baseDirectory>platform</baseDirectory>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>com.dcits.universe:remote</include>
</includes>
<binaries>
<outputDirectory>kernel</outputDirectory>
<unpack>false</unpack>
<includeDependencies>false</includeDependencies>
</binaries>
</moduleSet>
</moduleSets>
</assembly>
其中,moduleSet专门用于这种maven父子模块的场景,用于将包含的模块打包到指定目录下,在这里就是outputDirectory所配置的内容。
但是在多层次的父子模块中,比如图一所示,kernel-distribution只是构建出自己这一层次的目录结构。因为有多层次的目录结构,那么就需要在每一个层次上加一个distribution,来帮助构建这一层次的目录结构。
如图一所示,universe-distribution和kernel-distribution没有任何关系,但是显然universe-distribution需要包含kernel-distribution构建的内容。
因此,其assembly.xml的定义如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>core</id>
<formats>
<format>zip</format>
</formats>
<baseDirectory>platform</baseDirectory>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<includes>
<include>*/**</include>
</includes>
<directory>../L1-kernel/L1-kernel-distribution/target/L1-kernel-distribution-${version}-kernel</directory>
<outputDirectory>platform</outputDirectory>
</fileSet>
<fileSet>
<includes>
<include>*/**</include>
</includes>
<directory>../environment</directory>
<outputDirectory>environment</outputDirectory>
</fileSet>
<fileSet>
<includes>
<include>*/**</include>
</includes>
<directory>../configuration</directory>
<outputDirectory>configuration</outputDirectory>
</fileSet>
<fileSet>
<includes>
<include>*/**</include>
</includes>
<directory>../bin</directory>
<outputDirectory>bin</outputDirectory>
</fileSet>
</fileSets>
</assembly>
因为在定义上层模块的时候,universe-distribution是最后一个模块。
<modules>
<module>L1-kernel</module>
<module>L2-infrastructure</module>
<module>L3-operatingFramework</module>
<module>client</module>
<module>universe-distribution</module>
</modules>
这样,在maven构建的时候,可以保证之前所有的模块都已经构建完成。因此这里只需要拷贝文件即可。当然,这种方式略显粗糙,但是,基本思路就这样了,以后再优化。
这样的打包方式很类似之前spring的发布包的方式,一个zip包包含所有的spring的jar与源码,文档等,而且进行分目录的排列。但是现在spring的版本都是通过maven来发布,不再直接发布这种zip包,后续等持续集成环境搭建完毕后再考虑这种方式。
maven学习(二)的更多相关文章
- Maven学习 二 Maven环境搭建
第一步:下载Maven并解压 注意选择镜像地址,选择国内的会快点 解压目录 Maven目录分析 bin:含有mvn运行的脚本 boot:含有plexus-classworlds类加载器框架 conf: ...
- maven学习二(dependencies)
在前面一篇文章maven学习一(HelloWorld工程)已经对maven有了基本介绍,本文开始介绍maven依赖,通过如何如何增加log4j来学习maven的dependencies no-depe ...
- Maven学习 (二) Eclipse 上安装 Maven3插件
eclipse 安装插件的方式最常见的有两种: 1. 一种是在线安装,这貌似是用的最多的,就是:Help --> Install New Software,然后输入 HTTP 地址来安装,但 ...
- Maven学习二:使用Nexus搭建Maven私服及相关配置
处于安全等原因的考虑,一些企业内部网络是不允许访问外部网络的,但是项目内部搭建的项目又是Maven架构,这样就需要企业在内部网络中搭建自己的Maven仓库服务,再者一些大型企业或者内部模块化组件化划分 ...
- Maven学习(二)-----Maven启用代理访问
Maven启用代理访问 如果你的公司正在建立一个防火墙,并使用HTTP代理服务器来阻止用户直接连接到互联网.如果您使用代理,Maven将无法下载任何依赖. 为了使它工作,你必须声明在 Maven 的配 ...
- Maven学习系列二(1-5)
Maven学习系列二(1-5) 本文转自 QuantSeven 博客,讲解精炼易懂,适合入门,链接及截图如下 http://www.cnblogs.com/quanyongan/category/47 ...
- (转)Maven学习总结(二)——Maven项目构建过程练习
孤傲苍狼 只为成功找方法,不为失败找借口! Maven学习总结(二)——Maven项目构建过程练习 上一篇只是简单介绍了一下maven入门的一些相关知识,这一篇主要是体验一下Maven高度自动化构建项 ...
- maven学习之二M2_HOME简介
在<maven学习之一>中介绍了M2_HOME指向了maven的安装目录,如下图: weiwan..................
- Maven 学习笔记(二)
前面一文——Maven 学习笔记(一)中已经提到了 pom 的大部分配置,Maven 本质上是一个插件框架,它的核心并不执行任何具体的构建任务,所有这些任务都交给创建来完成,每一个任务都会对应一个插件 ...
- Maven学习笔记-03-Eclipse下maven项目在Tomcat7和Jetty6中部署调试
现在最新的Eclipse Luna Release 已经内置了Maven插件,这让我们的工作简洁了不少,只要把项目直接导入就可以,不用考虑插件什么的问题,但是导入之后的项目既可以部署在Tomcat也可 ...
随机推荐
- List转换成Json、对象集合转换Json等
#region List转换成Json /// <summary> /// List转换成Json /// </summary> public static string Li ...
- BFC--绝对值得你思考
CSS BFC(Block Formatting Context) BFC是W3C CSS 2.1规范中的一个概念,他决定了元素如何对其内容进行定位,以及与其他元素的关系和相互作用. ...
- Canvas入门(2):图形渐变和图像形变换
来源:http://www.ido321.com/986.html 一.图形渐变(均在最新版Google中测试) 1.绘制线性渐变 1: // 获取canvas 的ID 2: var canvas = ...
- flash图标插件
http://pullmonkey.com/projects/open_flash_chart2/
- RabbitMQ 入门 Helloworld -摘自网络
本系列教程主要来自于官网入门教程的翻译,然后自己进行了部分的修改与实验,内容仅供参考. “Hello world” of RabbitMQ 1.Windows下RabbitMQ的安装 下载Erlang ...
- 转】Apache解决高并发和高可用
原博主于: http://www.ha97.com/5803.html 感谢! 服务器集群 Apache 和 nginx(web服务器) 1. 多台集群机器联合处理一个任务. 2. 一台机器处 ...
- ZOJ 3911 Prime Query(线段树)
Prime Query Time Limit: 1 Second Memory Limit: 196608 KB You are given a simple task. Given a s ...
- HDU 2296 Ring (AC自动机+DP)
Ring Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- linux中vi编辑器
vi编辑器,通常称之为vi,是一种广泛存在于各种UNIX和Linux系 统中的文本编辑程序.它的功能十分强大,但是命令繁多,不容易掌握,它可以执行输出.删除.查找.替换.块操作等众多文本操作,而且用户 ...
- K - 最少拦截系统
Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不 能超过前一发的高度.某天,雷达 ...