maven分层项目
来源:互联网 发布:adobe cc 2015.5 mac 编辑:程序博客网 时间:2024/05/19 10:42
上一篇记录了maven项目的创建,由于现在项目都是分层搭建,这次记录一篇maven分层项目的创建。参考的http://www.cnblogs.com/xdp-gacl/p/4242221.html。感谢这位大神的分享。
项目结构:system-parent, system-domain, system-dao, system-service, system-web. web依赖service, service 依赖dao, dao依赖domain。parent把这几个模块总括起来。
1.创建system-parent:
mvn archetype:generate -DgroupId=moin -DartifactId=system-parent -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
注:原文archetype:create,在新版本的maven中会报错,generate没有问题。
执行后会生成一个src目录和pom.xml文件。parent只保留pom.xml将src删除。
system-parent的pom.xml如下:
<?xmlversion="1.0"encoding="UTF-8"?>
<projectxmlns="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>moin</groupId>
<artifactId>system-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>system-parent</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
2.创建system-domain:
将目录切换到system-parent下,执行命令:
mvn archetype:generate -DgroupId=moin -DartifactId=system-domain -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
system-domain的pom文件如下:
<?xmlversion="1.0"?>
<projectxsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>moin</groupId>
<artifactId>system-domain</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>system-domain</artifactId>
<packaging>jar</packaging>
<name>system-domain</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
3,创建system-dao:
将目录切换到system-parent下,执行命令:
mvn archetype:generate -DgroupId=moin -DartifactId=system-dao -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
system-dao的pom.xml文件如下:
<?xmlversion="1.0"?>
<projectxsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>moin</groupId>
<artifactId>system-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>system-dao</artifactId>
<packaging>jar</packaging>
<name>system-dao</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>moin</groupId>
<artifactId>system-domain</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
4,创建system-service
方法与system-dao相同,注意pom.xml中依赖于system-dao模块。
5,创建system-web.
切换到system-parent目录下,执行命令:
mvn archetype:generate -DgroupId=moin -DartifactId=system-web -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
system-web的pom.xml如下:<?xmlversion="1.0"?>
<projectxsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>moin</groupId>
<artifactId>system-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>system-web</artifactId>
<packaging>war</packaging>
<name>system-webMaven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>moin</groupId>
<artifactId>system-service</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<finalName>system-web</finalName>
<plugins>
<!--配置Jetty插件-->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
注意:packaging为war.src的webapp下会默认生成一个index.jsp。此时system-parent的pom.xml文件如下:
<?xmlversion="1.0"encoding="UTF-8"?>
<projectxmlns="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>moin</groupId>
<artifactId>system-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>system-parent</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<modules>
<module>system-domain</module>
<module>system-dao</module>
<module>system-service</module>
<module>system-web</module>
</modules>
</project>
parent会将domain,dao,service,web5个模块包含进来。然后将项目引入到eclipse中,就会看见分模块的maven项目。- maven分层项目
- 基本maven web项目的分层描述
- 用maven创建多模块项目,分层开发
- linux 环境下 用maven 创建项目(子项目分层创建)springMVC项目
- linux 环境下 用maven 创建项目(子项目分层创建)springMVC项目
- eclipse中手动创建像maven项目那样的分层目录
- 项目分层的困惑
- java项目分层思想
- 分层构建项目
- iOS项目分层
- angular项目如何分层
- WEB项目分层详解
- android项目分层解析
- 项目分层 facade service
- WEB项目的分层结构
- Desktop项目MVC分层分析
- Java Web项目包分层
- Myeclipse项目包的分层
- Android中单个View的触摸事件分发机制
- 解析xml
- RF网上资料
- 国家项目答辩PPT注意事项
- 常用正则表达式大全 -- 正则表达式基本语法
- maven分层项目
- C/C++ 内存泄漏检测工具 Visual Leak Detector
- javascript构造函数中的公有,私有,特权和静态成员
- TableView 点击项目后恢复原来状态
- tomcat 二级域名 session共享
- 快速搭建Ubuntu更新源服务器
- 如何检查C++中的内存泄漏 vs自带
- 关于STM32 NVIC配置的解释
- valueAsNumber将字符串转化成数字,number属性