项目使用IDEA进行构建,源码将会提交到GitHub上,使用Eclipse的用户也可以轻松导入。
在此我们将项目划分为4块,分别为model、dao、service和controller。
一、创建父模块
打开IDEA创建项目
点击Maven直接选择Next
补全GroupId与ArtifactId
填写项目名称与存放本地地址
此时项目结构如图
二、创建model子模块
如图
在此因为是普通的子模块所以我们还是直接next
接着填写ArtifactId
填写Module name接着finish
最终项目结构如下图所示
创建dao、service这两个子模块与model一样
最终项目结构如图
三、创建子模块controller
还是先创建Module
然后选择webapp
接着填写ArtifactId
接下来是Maven的配置,可以参考Maven 环境变量设置---------IDEA配置maven
点击finish多模块的框架就基本上搭建好了
如图所示
四、每个模块中依赖的配置
配置mytest-model中的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>mytest-root</artifactId>
<groupId>com.songci</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>mytest-model</artifactId>
<!--添加start-->
<packaging>jar</packaging>
<!--添加end-->
</project>
配置mytest-dao中的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>mytest-root</artifactId>
<groupId>com.songci</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>mytest-dao</artifactId>
<!--添加start-->
<packaging>jar</packaging>
<!--添加对mytest-model的依赖-->
<dependencies>
<dependency>
<groupId>com.songci</groupId>
<artifactId>mytest-model</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<!--添加end-->
</project>
配置mytest-service中的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>mytest-root</artifactId>
<groupId>com.songci</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>mytest-service</artifactId>
<!--添加start-->
<packaging>jar</packaging>
<dependencies>
<!--添加对mytest-model的依赖-->
<dependency>
<groupId>com.songci</groupId>
<artifactId>mytest-model</artifactId>
<version>${project.version}</version>
</dependency>
<!--添加对mytest-dao的依赖-->
<dependency>
<groupId>com.songci</groupId>
<artifactId>mytest-dao</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<!--添加end-->
</project>
配置mytest-web中的pom.xml
<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">
<parent>
<artifactId>mytest-root</artifactId>
<groupId>com.songci</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>mytest-web</artifactId>
<packaging>war</packaging>
<name>mytest-web Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!--添加start-->
<!--添加对mytest-model的依赖-->
<dependency>
<groupId>com.songci</groupId>
<artifactId>mytest-model</artifactId>
<version>${project.version}</version>
</dependency>
<!--添加对mytest-dao的依赖-->
<dependency>
<groupId>com.songci</groupId>
<artifactId>mytest-dao</artifactId>
<version>${project.version}</version>
</dependency>
<!--添加对mytest-service的依赖-->
<dependency>
<groupId>com.songci</groupId>
<artifactId>mytest-service</artifactId>
<version>${project.version}</version>
</dependency>
<!--添加end-->
</dependencies>
<build>
<finalName>mytest-web</finalName>
</build>
</project>
配置mytest_one中的pom.xml(就是最外面那个pom.xml)
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.songci</groupId>
<artifactId>mytest-root</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>mytest-model</module>
<module>mytest-dao</module>
<module>mytest-service</module>
<module>mytest-web</module>
</modules>
<!--添加start-->
<!--项目统一字符集编码-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!--添加end-->
</project>
以上maven多模块就搭建好了,接下来我们在该项目基础上对Spring、SpringMVC、Mybatis进行整合
下一篇
Maven-maven多模块项目搭建+SSM框架整合((二、Dao层添加测试,服务层添加))
GitHub地址:https://github.com/iamsongci/mytest_one
未完待续--------
热门评论
厉害,,very good!!!
厉害,,very good!!!
厉害,very,good