为了兼容之前基于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学习(二)的更多相关文章

  1. Maven学习 二 Maven环境搭建

    第一步:下载Maven并解压 注意选择镜像地址,选择国内的会快点 解压目录 Maven目录分析 bin:含有mvn运行的脚本 boot:含有plexus-classworlds类加载器框架 conf: ...

  2. maven学习二(dependencies)

    在前面一篇文章maven学习一(HelloWorld工程)已经对maven有了基本介绍,本文开始介绍maven依赖,通过如何如何增加log4j来学习maven的dependencies no-depe ...

  3. Maven学习 (二) Eclipse 上安装 Maven3插件

    eclipse 安装插件的方式最常见的有两种: 1. 一种是在线安装,这貌似是用的最多的,就是:Help  -->  Install New Software,然后输入 HTTP 地址来安装,但 ...

  4. Maven学习二:使用Nexus搭建Maven私服及相关配置

    处于安全等原因的考虑,一些企业内部网络是不允许访问外部网络的,但是项目内部搭建的项目又是Maven架构,这样就需要企业在内部网络中搭建自己的Maven仓库服务,再者一些大型企业或者内部模块化组件化划分 ...

  5. Maven学习(二)-----Maven启用代理访问

    Maven启用代理访问 如果你的公司正在建立一个防火墙,并使用HTTP代理服务器来阻止用户直接连接到互联网.如果您使用代理,Maven将无法下载任何依赖. 为了使它工作,你必须声明在 Maven 的配 ...

  6. Maven学习系列二(1-5)

    Maven学习系列二(1-5) 本文转自 QuantSeven 博客,讲解精炼易懂,适合入门,链接及截图如下 http://www.cnblogs.com/quanyongan/category/47 ...

  7. (转)Maven学习总结(二)——Maven项目构建过程练习

    孤傲苍狼 只为成功找方法,不为失败找借口! Maven学习总结(二)——Maven项目构建过程练习 上一篇只是简单介绍了一下maven入门的一些相关知识,这一篇主要是体验一下Maven高度自动化构建项 ...

  8. maven学习之二M2_HOME简介

    在<maven学习之一>中介绍了M2_HOME指向了maven的安装目录,如下图: weiwan..................

  9. Maven 学习笔记(二)

    前面一文——Maven 学习笔记(一)中已经提到了 pom 的大部分配置,Maven 本质上是一个插件框架,它的核心并不执行任何具体的构建任务,所有这些任务都交给创建来完成,每一个任务都会对应一个插件 ...

  10. Maven学习笔记-03-Eclipse下maven项目在Tomcat7和Jetty6中部署调试

    现在最新的Eclipse Luna Release 已经内置了Maven插件,这让我们的工作简洁了不少,只要把项目直接导入就可以,不用考虑插件什么的问题,但是导入之后的项目既可以部署在Tomcat也可 ...

随机推荐

  1. Selenium IDE验证点

    Selenium IDE验证点 我们还开发了测试用例需要检查一个Web页面的属性.这需要维护和验证命令.有两种方法可以验证点到任何脚本 插入记录模式中的任何验证点单击“右键”元素,并选择“Show a ...

  2. flex 图片旋转(解决公转和自转问题)

    在Flex中图片的旋转是既有公转和自转的.这样在图片旋转的时候就有一定小麻烦: 为了更好地说明问题,先引入两个概念:“自转”和“公转”.想象一下,地球在绕着太阳公转的同时,它自己也在自转.Flash应 ...

  3. 建立简单的VLAN通信

    http://minitoo.blog.51cto.com/4201040/786011(转载) 在路由器上做单臂路由实现VLAN间路由,也就是设置子接口和封装协议. 实现环境如下图: 在交换机上建立 ...

  4. ORA-15018: diskgroup cannot be created

    创建ASM磁盘组的时候出错,具体报错如下: SQL> create diskgroup kel external redundancy disk 'ORCL:KEL1','ORCL:KEL2'; ...

  5. Windows 8.1及Windows8 JDK环境变量配置

    一.首先安装JDK JDK:http://www.oracle.com/technetwork/cn/java/javase/downloads/index.html 根据操作系统选择相应的版本 二. ...

  6. 多线程之 CountDownLatch

    CountDownLatch,一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待. CountDownLatch如其所写,是一个倒计数的锁存器,当计数减至0时触发特定 ...

  7. redis.conf的配置

    daemonize yes   :  redis server 实例是否以后台方式运行 , no:不以后台方式运行(默认) , yes:以后台方式运行. requirepass 密码 :  密码最好长 ...

  8. libvirt虚拟系统如何增加usb设备

    之前干这些事情都是通过virt-manager来搞定的.不过由于这个图形界面不太方便,而且现在没法打开(具体原因不详,每次打开提示一些方法未实现什么的),所以试下用libvirt的命令virsh来搞定 ...

  9. Sqoop 命令

    1)list-databases     List available databases on a server sqoop list-databases --connect jdbc:db2:// ...

  10. Spring Autowiring by AutoDetect

    In Spring, "Autowiring by AutoDetect", means chooses "autowire by constructor" i ...