Maven管理多模块项目
首先,我们要明确的多模块项目的含义,它是指一个应用中包含多个module。一般来说,一个应用单独部署成服务,只是打包的时候,maven会把各个module组合在一起。各模块一般单独打成jar放到lib目录中,当然web应用也生成war包。
这里说的多模块项目要与那种单独自立门户的多个application区分开来,多个application也可能有包级的关联,但是它们各自分开了,不属于多模块项目的范畴。
maven对多模块项目的管理大概是这样的,它存在一个parent模块,但实际没有程序代码,只包含一个pom.xml,该pom是用来给子模块来引用的。
目录结构与下面的类似:
simple-parent
+-simple-weather
+-src
+-target
\-pom.xml
+-simple-webapp
+-src
+-target
\-pom.xml
\-pom.xml
在这个目录结构中,一个父模块包含了两个子模块。
各个pom.xml的内容大致如下:
pom.xml:
- <modules>
- <groupId>org.sonatype.mavenbook.multi</groupId>
- <artifactId>parent</artifactId>
- <version>0.8-SNAPSHOT</version>
- <packaging>pom</packaging>
- <module>simple-weather</module>
- <module>simple-webapp</module>
- </modules>
- <dependencies>
- <dependency>
- <groupId>velocity</groupId>
- <artifactId>velocity</artifactId>
- <version>1.5</version>
- </dependency>
- </dependencies>
simple-weather/pom.xml:
- <parent>
- <groupId>org.sonatype.mavenbook.multi</groupId>
- <artifactId>simple-parent</artifactId>
- <version>0.8-SNAPSHOT</version>
- </parent>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
simple-webapp/pom.xml:
- <parent>
- <groupId>org.sonatype.mavenbook.multi</groupId>
- <artifactId>simple-parent</artifactId>
- <version>0.8-SNAPSHOT</version>
- </parent>
- <dependencies>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-servlet_2.4_spec</artifactId>
- <version>1.1.1</version>
- </dependency>
- </dependencies>
如果按父pom.xml打包,会输出 simple-weather**.jar,simple-webapp**.war两个包;
如果按simple-weather/pom.xml打包,则只会输出 simple-weather**.jar;
如果按simple-webapp/pom.xml打包,则只会输出 simple-webapp**.war。
另外,子模块会继承父模块的包依赖,使用mvn dependency:tree可以查看各个模块的包依赖列表,simple-weather,simple-webapp项目都有引用到 velocity包。
虽然这是一个application下包含了多个module的结构,但是在eclipse中,还是得对每个子module单独建project来管理源码。具体可以分别在simple-weather、simple-webapp目录下使用mvn eclipse:eclipse来创建eclipse project,创建完毕后,你就可以在文件.classpath中看到,包依赖关系已经按照pom.xml中的配置自动生成了。
Maven管理多模块项目的更多相关文章
- SSH框架之一详解maven搭建多模块项目
闲来无事,思量着自己搭建一个ssh框架,一来回顾熟悉一下ssh的内容,hibernate还就没用过了,生疏了都.二来整合一下,将其他掌握的和正在学习的框架核技术糅合到一起,就当是做一个demo练手了. ...
- Maven管理 划分模块
转载地址:juvenshun.iteye.com/blog/305865 “分天下为三十六郡,郡置守,尉,监” —— <史记·秦始皇本纪> 所有用Maven管理的真实的项目都应该是分模块的 ...
- maven 配置多模块项目 pom modules
所有用Maven管理的真实的项目都应该是分模块的,每个模块都对应着一个pom.xml.它们之间通过继承和聚合(也称作多模块,multi-module)相互关联.那么,为什么要这么做呢?我们明明在开发一 ...
- 使用Maven构建多模块项目
[转] 使用Maven构建多模块项目 在平时的Javaweb项目开发中为了便于后期的维护,我们一般会进行分层开发,最常见的就是分为domain(域模型层).dao(数据库访问层).service(业务 ...
- maven导入多模块项目
maven导入多模块项目 一.SVN上Maven多模块项目结构 使用eclipse导入SVN上的Maven多模块项目 Maven多模块项目所在SVN目录 二.eclipse通过SVN导入到工作空间 ...
- Maven学习(五)使用Maven构建多模块项目
使用Maven构建多模块项目 一般的web项目构成: 建立解决方案目录parent 首先使用命令进入到我们需要建立maven项目的目录: mvn archetype:generate -DgroupI ...
- (转)Maven学习总结(八)——使用Maven构建多模块项目
孤傲苍狼只为成功找方法,不为失败找借口! Maven学习总结(八)——使用Maven构建多模块项目 在平时的Javaweb项目开发中为了便于后期的维护,我们一般会进行分层开发,最常见的就是分为doma ...
- Spring-在IDEA2016中创建maven管理的SpringMVC项目
这是一套我自己摸索出来的创建项目方法,基本是用在创建用maven管理的 Spring+SpringMVC+Mybatis的J2EE项目时. 创建一个maven管理的webapp项目 在创建项目时,选择 ...
- Maven创建多模块项目(包括依赖版本号的统一更新)
0.多项目工程的文件夹及依赖关系 bus-core-api为公共项目,app-web-ui依赖bus-core-api,app-desktop-ui依赖bus-core-api 1.创建一个父Mave ...
随机推荐
- 239. Sliding Window Maximum
题目: Given an array nums, there is a sliding window of size k which is moving from the very left of t ...
- 在Tomcat中配置数据源
使用工具:TOMCAT 7.0.52.IntelliJ IDEA 13.0.2.JSF 2.0+.SqlServer.jtds-1.2.5.jar 搞了好久都没成功,开始使用注解引入DataSourc ...
- 用matlab训练数字分类的深度神经网络Training a Deep Neural Network for Digit Classification
This example shows how to use Neural Network Toolbox™ to train a deep neural network to classify ima ...
- 从输入 URL 到页面加载完的过程中都发生了什么---优化
这篇文章是转载自:安度博客,http://www.itbbu.com/1490.html 在很多地方看到,感觉不错,理清了自己之前的一些思路,特转过来留作记录. 一个HTTP请求的过程 为了简化我们先 ...
- C#6.0 VS2015
https://msdn.microsoft.com/en-us/library/hh156499(v=vs.140).aspx This page lists key feature names f ...
- Linux改IP后务必重启网络服务
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0BOOTPROTO=noneONBOOT=yes ...
- TC SRM 593 DIV1 250(dfs)
这图最多3色就可以 搜2就行了 #include <iostream> #include<cstdio> #include<cstring> #include< ...
- Save output to a text file from Mac terminal
Simply with output redirection: system_profiler > file.txt Basically, this will take the output ...
- CocoaPods requires your terminal to be using UTF-8 encoding
WARNING: CocoaPods requires your terminal to be using UTF-8 encoding. See https://github.com/CocoaPo ...
- uva580Critical Mass
递推. 用f[i]代表i个盒子的放法,设g[i]=2^n-f[i],代表i个盒子不满足条件的放法. 枚举第一个U所在的位置j.则方法有g[j-2]*(2^(i-j-2))种,j-1必须是L. 所以 ...