我们先在eclipse中新建一个maven项目,pom.xml的文件如下:

搭建多模块项目,必须要有一个packaging为pom的根目录。创建好这个maven项目后,我们对着项目右键-->new

输入你的项目名称

这里就不重复说创建项目了,创建好的目录结构在eclipse中如下:

说明一下这些项目具体都是干嘛的:

easyframework-model:数据模型,与数据库表字段对应的实体类

easyframework-core:核心业务项目。主要是Service处理业务逻辑

easyframework-persist:数据持久层,操作低层数据库。

easyframework-utils:工具类,所有工具类都提取出来写在这个项目中。

easyframework-web :这个就是整个项目的web层了,页面的显示以及控制层

备注:创建这些项目的时候,只有easyframework-web是web项目即maven的:maven-archetype-webapp,其他的都是java项目:maven-archetype-quicktart

打开easyframework-root的pom.xml文件,你会看到模块化是这样的:

接下来是配置各个模块的依赖关系,我个人认为的项目是这样依赖的,不知道对不对,呵呵....

举个例子easyframework-web这个项目依赖easyframework-core(业务核心)和easyframework-model(实体类),easyframework-utils(公共的工具类)这个三个模块。

那么在怎么在easyframework-web的pom.xml中体现呢,具体如下:

打开项目的maven依赖你会发现,已经依赖了这三个项目

但是你应该会感觉到奇怪,为什么会有那么jar包,明明只引用了这三个项目,哪来的那么多jar包。

你会发现,我再pom.xml文件中,有个parent节点,继承了根节点的pom,这就是maven的项目继承依赖,会从父POM中继承一些值。这对构建一个大型的系统来说很有必要

这样的话你就不需要一遍又一遍的重复添加同样的依赖元素,当然,如果你在子项目中也有同样的依赖,则会覆盖父POM中的值。

父POM的的依赖如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.easyframework</groupId>
<artifactId>easyframework-root</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>easyframework-root</name>
<url>http://maven.apache.org</url>
<modules>
<module>easyframework-web</module>
<module>easyframework-persist</module>
<module>easyframework-core</module>
<module>easyframework-utils</module>
<module>easyframework-model</module>
</modules>
<properties>
<!--指定Maven用什么编码来读取源码及文档 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!--指定Maven用什么编码来呈现站点的HTML文件 -->
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<mysql.version>5.1.25</mysql.version>
<hibernate.version>4.2.2.Final</hibernate.version>
<spring.version>3.2.3.RELEASE</spring.version>
<aspectj.version>1.7.2</aspectj.version>
</properties>
<repositories>
<repository>
<id>springsource-repo</id>
<name>SpringSource Repository</name>
<url>http://repo.springsource.org/release</url>
</repository>
</repositories>
<dependencies> <!-- log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- mysql数据库驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!-- hibernate4 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
<!-- spring3 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<build>
<finalName>easyframework-root</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

当然这个父POM只是一个例子,你可以根据自己的配置添加相关的依赖,这里给一个我认为是最好用的仓库:

http://mvnrepository.com/ 相信地球人都知道这个!哈哈.....

到此就搭建好了企业级多模块的项目环境了。

Maven学习--- 搭建多模块企业级项目的更多相关文章

  1. 使用maven命令搭建多模块企业级项目

    http://www.cnblogs.com/xdp-gacl/p/4242221.html

  2. Maven学习 (六) 搭建多模块企业级项目

    首先,前面几次学习已经学会了安装maven,如何创建maven项目等,最近的学习,终于有点进展了,搭建一下企业级多模块项目. 好了,废话不多说,具体如下: 首先新建一个maven项目,pom.xml的 ...

  3. [转] 用Maven搭建多模块企业级项目

    转自:http://www.cnblogs.com/quanyongan/archive/2013/05/28/3103243.html 首先,前面几次学习已经学会了安装maven,如何创建maven ...

  4. maven搭建多模块企业级项目

    首先,前面几次学习已经学会了安装maven,如何创建maven项目等,最近的学习,终于有点进展了,搭建一下企业级多模块项目. 好了,废话不多说,具体如下: 首先新建一个maven项目,pom.xml的 ...

  5. [maven] 搭建多模块企业级项目

    知识点:聚合.继承.工程依赖.单元测试.多war聚合.cargo发布 ① 准备工作 参考资料 http://www.cnblogs.com/quanyongan/archive/2013/05/28/ ...

  6. maven(多个模块)项目 部署 开发环境 问题处理历程【异常Name jdbc is not bound in this Context 异常java.lang.NoSuchMethodE】

    maven(多个模块)项目 部署 开发环境 问题处理历程[异常Name jdbc is not bound in this Context 异常java.lang.NoSuchMethodE] 201 ...

  7. maven学习-搭建环境

    1.Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具. 2.下载: maven.apache.org 3.bin目录包含mvn的运行脚本: ...

  8. Maven 学习笔记——将普通的Java项目转换成Maven项目(3)

    将一个普通的java项目转换成Maven项目并不是一个很大的任务,仅仅只需要下面的几步就能将转换成功.下面我是用一个简单的Selenium测试小demon作为例子来说的. 移调项目中所有关联的Libr ...

  9. Spring框架学习-搭建第一个Spring项目

    步骤一:下载Spring开发包. 官网:https://spring.io/           下载地址:https://repo.spring.io/libs-release-local/org/ ...

随机推荐

  1. DFS csu1719 Boggle

    传送门:id=1719">点击打开链接 题意:真正的题意是,告诉你一些字符串.然后告诉你非常多个字符格子,问这些字符串是否能在字符格子中连起来,在格子中对角线也觉得是连在一起的.假设格 ...

  2. angularJS 事件广播与接收[转]

    路由的事件 事件这个词在前端出现的频率真是高,根本拦不住,哪都是.$route服务在路由过程中的每个阶段都会触发不同的事件,可以为这些不同的路由事件设置监听器并做出响应. 一共有4个事件用来监听路由的 ...

  3. 使用sphinx自动提取python中的注释成为接口文档

    写好了代码,交付给他人使用的时候,查看代码固然可以了解各类和函数的功能细节,但接口文档能更方便的查找和说明功能.所以,一价与代码同步的接口文档是很有必要的.sphinx可以根据python中的注释,自 ...

  4. TP - 001

  5. 移动端H5的一些基本知识点总结

    移动端H5的一些基本知识点总结 来到这家公司之后,和曾经的工作发生了非常大的转变.曾经我一直是做PC端页面的.来到如今这家公司之后,主要是做手机移动端的页面. 移动端的页面在我这个做习惯了PC端页面的 ...

  6. VB.NET版+三层实现登陆

    三层已经学了一些时间了,開始认为自己能够用C#敲代码了,就用C#写了一个实现登陆的,真正再用在机房中.还是认为非常吃力的,所以.决定用vb.net敲了.以下是我用vb.net实现的登陆.能够给大家做一 ...

  7. 不同版本的tomcat下载路径

    1.由于安全问题,有些tomcat存在漏洞.为了升级要么修复漏洞,要么就直接升级tomcat. 一般升级tomcat比较省事.但是找到相应版本的tomcat比较难,所以还是要自己寻找对应的tomcat ...

  8. mybatis-generator生成逆向工程两种方式

    本文博客地址:http://blog.csdn.net/soonfly/article/details/64499423 逆向工程下载 链接:https://pan.baidu.com/s/1YOAq ...

  9. redhat7.0安装ifconfig

    问题描述: Setup is unable to find the "ifconfig" program on your machine. Please make sure it ...

  10. Arduino从DHT11读取温湿度数据并显示在1602LCD

    硬件清单 Arduino NANO1602LCD + PCF8574T模块YL-47 DHT11模块 连线 1. 连接LCD: PCF8574T模块4pin(Gnd, Vcc, SDA i2c数据, ...