Eclipse下使用maven搭建多模块项目
暂时将项目分为如下几层:
domain(域模型层)、dao(数据库访问层)、service(业务逻辑层)、web(表现层),有需要再另行添加(如common等);
目录结构:
一、app
该层为父层,管理其它模块层。
1.1 创建Maven Project
1.2 选择maven-archetype-quickstart
1.3 删除src文件夹,修改pom.xml文件,将<packaging>jar</packaging>修改为<packaging>pom</packaging>,pom表示它是一个被继承的模块
修改之后的配置文件:
二、app-domain
2.1 创建Maven Module
2.2 选择maven-archetype-quickstart
2.3 修改app-domain目录中的pom.xml文件,把<groupId>com.bdong</groupId>和<version>0.0.1-SNAPSHOT</version>去掉,加上<packaging>jar</packaging>,groupId和version会继承app中的groupId和version,packaging设置打包方式为jar
修改后的配置文件:
3.1 创建Maven Module
3.2 选择maven-archetype-quickstart
3.3 修改app-dao目录中的pom.xml文件,,把<groupId>com.bdong</groupId>和<version>0.0.1-SNAPSHOT</version>去掉,加上<packaging>jar</packaging>,因为groupId和version会继承app中的groupId和version,packaging设置打包方式为jar,同时添加对app-domain模块的依赖
修改后的配置文件:
4.1 创建Maven Module
4.2 选择maven-archetype-quickstart
4.3 修改app-service目录中的pom.xml文件,,把<groupId>com.bdong</groupId>和<version>0.0.1-SNAPSHOT</version>去掉,加上<packaging>jar</packaging>,packaging设置打包方式为jar,同时添加对app-dao模块的依赖,app-service依赖app-dao和app-domain,但是只需添加app-dao的依赖即可,因为app-dao已经依赖了app-domain。
修改后的配置文件:
5.1 创建Maven Module
5.2 选择maven-archetype-webapp
5.3 修改app-web目录中的pom.xml文件,,把<groupId>com.bdong</groupId>和<version>0.0.1-SNAPSHOT</version>去掉,修改打包方式为<packaging>war</packaging>,添加对app-service模块的依赖
修改后的配置文件:
六,编译
控制台打印信息:
七、运行
7.1 添加app-web到tomcat中
7.2 运行tomcat,然后在浏览器中访问:localhost:8080/app-web
最终,目录结构为:
使用命令搭建多模块可参考:http://www.cnblogs.com/xdp-gacl/p/4242221.html