maven实现多模块项目整合

淘淘商城

    1.功能架构

        1.1 系统功能图

                maven实现多模块项目整合_第1张图片

        1.2 功能描述

                后台管理系统:管理商品、订单、类目、商品规格属性、用户管理以及内容发布等功能。
                前台系统:用户可以在前台系统中进行注册、登录、浏览商品、首页、下单等操作。
                会员系统:用户可以在该系统中查询已下的订单、收藏的商品、我的优惠券、团购等信息。
                订单系统:提供下单、查询订单、修改订单状态、定时处理订单。
                搜索系统:提供商品的搜索功能。
                单点登录系统:为多个系统之间提供用户登录凭证以及查询登录用户的信息。

        1.3 主要技术

                + Spring、SpringMVC、Mybatis
                + JSP、JSTL、jQuery、jQuery plugin、EasyUI、KindEditor(富文本编辑器)、CSS+DIV
                + Redis(缓存服务器)
                + Solr(搜索)
                + httpclient(调用系统服务)
                + Mysql
                + Nginx(web服务器)

        1.4 开发工具和环境

                Eclipse 4.5.0(Mars),自带maven插件,需要手工安装svn插件。
                Maven 3.3.3(开发工具自带)
                Tomcat 7.0.53(Maven Tomcat Plugin)
                JDK 1.7
                Mysql 5.6
                Nginx 1.8.0
                Redis 3.0.0
                Win7 操作系统
                SVN(版本管理)

    2.后台管理系统工程结构

        2.1 Maven本地仓库

             在当前系统用户的文件夹下。例如当前用户是Administrator那么本地仓库就是在C:\Users\Administrator.m2目录下。(maven下载地址:https://maven.apache.org/download.cgi)
             (镜像仓库配置)修改maven的setting.xml配置,在mirrors节点下面添加子节点:

      <mirror>
          <id>nexus-aliyunid>
          <mirrorOf>centralmirrorOf>
          <name>Nexus aliyunname>
          <url>http://maven.aliyun.com/nexus/content/groups/publicurl> 
      mirror>

        2.2 后台管理系统的工程结构

    taotao-parent – 管理依赖jar包的版本,全局,公司级别
         |–taotao-common — 通用组件、工具类
         |–taotao-manage – 后台系统
             |–com.taotao.manage.web
             |–com.taotao.manage.service
             |–com.taotao.manage.mapper
             |–com.taotao.manage.pojo

        2.3 创建taotao-parent

                2.3.1创建maven工程
                maven实现多模块项目整合_第2张图片                maven实现多模块项目整合_第3张图片                2.3.2 修改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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0modelVersion>
	<groupId>com.taotaogroupId>
	<artifactId>taotao-parentartifactId>
	<version>0.0.1-SNAPSHOTversion>
	<packaging>pompackaging>
	
	<properties>
		<junit.version>4.12junit.version>
		<spring.version>4.1.3.RELEASEspring.version>
		<mybatis.version>3.2.8mybatis.version>
		<mybatis.spring.version>1.2.2mybatis.spring.version>
		<mybatis.paginator.version>1.2.15mybatis.paginator.version>
		<mysql.version>5.1.32mysql.version>
		<slf4j.version>1.6.4slf4j.version>
		<jackson.version>2.4.2jackson.version>
		<druid.version>1.0.9druid.version>
		<httpclient.version>4.3.5httpclient.version>
		<jstl.version>1.2jstl.version>
		<servlet-api.version>2.5servlet-api.version>
		<jsp-api.version>2.0jsp-api.version>
		<joda-time.version>2.5joda-time.version>
		<commons-lang3.version>3.3.2commons-lang3.version>
		<commons-io.version>1.3.2commons-io.version>
		<commons-net.version>3.3commons-net.version>
		<pagehelper.version>3.4.2pagehelper.version>
		<jsqlparser.version>0.9.1jsqlparser.version>
		<commons-fileupload.version>1.3.1commons-fileupload.version>
		<jedis.version>2.7.2jedis.version>
		<solrj.version>4.10.3solrj.version>
	properties>
	<dependencyManagement>
		<dependencies>
			
			<dependency>
				<groupId>joda-timegroupId>
				<artifactId>joda-timeartifactId>
				<version>${joda-time.version}version>
			dependency>
			
			<dependency>
				<groupId>org.apache.commonsgroupId>
				<artifactId>commons-lang3artifactId>
				<version>${commons-lang3.version}version>
			dependency>
			<dependency>
				<groupId>org.apache.commonsgroupId>
				<artifactId>commons-ioartifactId>
				<version>${commons-io.version}version>
			dependency>
			<dependency>
				<groupId>commons-netgroupId>
				<artifactId>commons-netartifactId>
				<version>${commons-net.version}version>
			dependency>
			
			<dependency>
				<groupId>com.fasterxml.jackson.coregroupId>
				<artifactId>jackson-databindartifactId>
				<version>${jackson.version}version>
			dependency>
			
			<dependency>
				<groupId>org.apache.httpcomponentsgroupId>
				<artifactId>httpclientartifactId>
				<version>${httpclient.version}version>
			dependency>
			
			<dependency>
				<groupId>junitgroupId>
				<artifactId>junitartifactId>
				<version>${junit.version}version>
				<scope>testscope>
			dependency>
			
			<dependency>
				<groupId>org.slf4jgroupId>
				<artifactId>slf4j-log4j12artifactId>
				<version>${slf4j.version}version>
			dependency>
			
			<dependency>
				<groupId>org.mybatisgroupId>
				<artifactId>mybatisartifactId>
				<version>${mybatis.version}version>
			dependency>
			<dependency>
				<groupId>org.mybatisgroupId>
				<artifactId>mybatis-springartifactId>
				<version>${mybatis.spring.version}version>
			dependency>
			<dependency>
				<groupId>com.github.miemiedevgroupId>
				<artifactId>mybatis-paginatorartifactId>
				<version>${mybatis.paginator.version}version>
			dependency>
			<dependency>
				<groupId>com.github.pagehelpergroupId>
				<artifactId>pagehelperartifactId>
				<version>${pagehelper.version}version>
			dependency>
			
			<dependency>
				<groupId>mysqlgroupId>
				<artifactId>mysql-connector-javaartifactId>
				<version>${mysql.version}version>
			dependency>
			
			<dependency>
				<groupId>com.alibabagroupId>
				<artifactId>druidartifactId>
				<version>${druid.version}version>
			dependency>
			
			<dependency>
				<groupId>org.springframeworkgroupId>
				<artifactId>spring-contextartifactId>
				<version>${spring.version}version>
			dependency>
			<dependency>
				<groupId>org.springframeworkgroupId>
				<artifactId>spring-beansartifactId>
				<version>${spring.version}version>
			dependency>
			<dependency>
				<groupId>org.springframeworkgroupId>
				<artifactId>spring-webmvcartifactId>
				<version>${spring.version}version>
			dependency>
			<dependency>
				<groupId>org.springframeworkgroupId>
				<artifactId>spring-jdbcartifactId>
				<version>${spring.version}version>
			dependency>
			<dependency>
				<groupId>org.springframeworkgroupId>
				<artifactId>spring-aspectsartifactId>
				<version>${spring.version}version>
			dependency>
			
			<dependency>
				<groupId>jstlgroupId>
				<artifactId>jstlartifactId>
				<version>${jstl.version}version>
			dependency>
			<dependency>
				<groupId>javax.servletgroupId>
				<artifactId>servlet-apiartifactId>
				<version>${servlet-api.version}version>
				<scope>providedscope>
			dependency>
			<dependency>
				<groupId>javax.servletgroupId>
				<artifactId>jsp-apiartifactId>
				<version>${jsp-api.version}version>
				<scope>providedscope>
			dependency>
			
			<dependency>
				<groupId>commons-fileuploadgroupId>
				<artifactId>commons-fileuploadartifactId>
				<version>${commons-fileupload.version}version>
			dependency>
			
			<dependency>
				<groupId>redis.clientsgroupId>
				<artifactId>jedisartifactId>
				<version>${jedis.version}version>
			dependency>
			
			<dependency>
				<groupId>org.apache.solrgroupId>
				<artifactId>solr-solrjartifactId>
				<version>${solrj.version}version>
			dependency>
		dependencies>
	dependencyManagement>

	<build>
		<finalName>${project.artifactId}finalName>
		<plugins>
			
			<plugin>
				<groupId>org.apache.maven.pluginsgroupId>
				<artifactId>maven-resources-pluginartifactId>
				<version>2.7version>
				<configuration>
					<encoding>UTF-8encoding>
				configuration>
			plugin>
			
			<plugin>
				<groupId>org.apache.maven.pluginsgroupId>
				<artifactId>maven-compiler-pluginartifactId>
				<version>3.2version>
				<configuration>
					<source>1.7source>
					<target>1.7target>
					<encoding>UTF-8encoding>
				configuration>
			plugin>
		plugins>
		<pluginManagement>
			<plugins>
				
				<plugin>
					<groupId>org.apache.tomcat.mavengroupId>
					<artifactId>tomcat7-maven-pluginartifactId>
					<version>2.2version>
				plugin>
			plugins>
		pluginManagement>
	build>
project>

                2.3.3 将taotao-parent安装到本地仓库
                maven实现多模块项目整合_第4张图片

        2.4 创建taotao-common

                2.4.1 创建工程
                maven实现多模块项目整合_第5张图片                2.4.2 修改pom文件
                         修改taotao-common工程的pom文件,在文件中添加对taotao-parent的继承。

<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.0modelVersion>
	<parent>
		<groupId>com.taotaogroupId>
		<artifactId>taotao-parentartifactId>
		<version>0.0.1-SNAPSHOTversion>
	parent>
	<groupId>com.taotaogroupId>
	<artifactId>taotao-commonartifactId>
	<version>0.0.1-SNAPSHOTversion>
	
	<dependencies>
		
		<dependency>
			<groupId>joda-timegroupId>
			<artifactId>joda-timeartifactId>
		dependency>
		
		<dependency>
			<groupId>org.apache.commonsgroupId>
			<artifactId>commons-lang3artifactId>
		dependency>
		<dependency>
			<groupId>org.apache.commonsgroupId>
			<artifactId>commons-ioartifactId>
		dependency>
		<dependency>
			<groupId>commons-netgroupId>
			<artifactId>commons-netartifactId>
		dependency>
		
		<dependency>
			<groupId>com.fasterxml.jackson.coregroupId>
			<artifactId>jackson-databindartifactId>
		dependency>
		
		<dependency>
			<groupId>org.apache.httpcomponentsgroupId>
			<artifactId>httpclientartifactId>
		dependency>
		
		<dependency>
			<groupId>junitgroupId>
			<artifactId>junitartifactId>
			<scope>testscope>
		dependency>
		
		<dependency>
			<groupId>org.slf4jgroupId>
			<artifactId>slf4j-log4j12artifactId>
		dependency>
	dependencies>
project>

                2.4.3 安装工程
                         同2.3.3操作

        2.5 创建taotao-manager

                maven实现多模块项目整合_第6张图片
                修改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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0modelVersion>
	<parent>
		<groupId>com.taotaogroupId>
		<artifactId>taotao-parentartifactId>
		<version>0.0.1-SNAPSHOTversion>
	parent>
	<groupId>com.taotaogroupId>
	<artifactId>taotao-managerartifactId>
	<version>0.0.1-SNAPSHOTversion>
	<packaging>pompackaging>
	
	<dependencies>
		<dependency>
			<groupId>com.taotaogroupId>
			<artifactId>taotao-commonartifactId>
			<version>0.0.1-SNAPSHOTversion>
		dependency>
	dependencies>
project>

        2.5.1 创建taotao-manager-pojomaven实现多模块项目整合_第7张图片

maven实现多模块项目整合_第8张图片maven实现多模块项目整合_第9张图片
maven实现多模块项目整合_第10张图片pom文件不需要修改,taotao-manager-pojo模块不依赖任何jar包。

        2.5.2 创建taotao-manager-mapper

maven实现多模块项目整合_第11张图片
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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0modelVersion>
	<parent>
		<groupId>com.taotaogroupId>
		<artifactId>taotao-managerartifactId>
		<version>0.0.1-SNAPSHOTversion>
	parent>
	<artifactId>taotao-manager-mapperartifactId>
	
	<dependencies>
		<dependency>
			<groupId>com.taotaogroupId>
			<artifactId>taotao-manager-pojoartifactId>
			<version>0.0.1-SNAPSHOTversion>
		dependency>
		
		<dependency>
			<groupId>org.mybatisgroupId>
			<artifactId>mybatisartifactId>
		dependency>
		<dependency>
			<groupId>org.mybatisgroupId>
			<artifactId>mybatis-springartifactId>
		dependency>
		<dependency>
			<groupId>com.github.miemiedevgroupId>
			<artifactId>mybatis-paginatorartifactId>
		dependency>
		<dependency>
			<groupId>com.github.pagehelpergroupId>
			<artifactId>pagehelperartifactId>
		dependency>
		
		<dependency>
			<groupId>mysqlgroupId>
			<artifactId>mysql-connector-javaartifactId>
		dependency>
		
		<dependency>
			<groupId>com.alibabagroupId>
			<artifactId>druidartifactId>
		dependency>
	dependencies>
	
	<build>
		<resources>
            <resource>
                <directory>src/main/javadirectory>
                <includes>
                    <include>**/*.propertiesinclude>
                    <include>**/*.xmlinclude>
                includes>
                <filtering>falsefiltering>
            resource>
        resources>
	build>
project>

        2.5.3 创建taotao-manager-service

maven实现多模块项目整合_第12张图片
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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0modelVersion>
	<parent>
		<groupId>com.taotaogroupId>
		<artifactId>taotao-managerartifactId>
		<version>0.0.1-SNAPSHOTversion>
	parent>
	<artifactId>taotao-manager-serviceartifactId>
	
	<dependencies>
		<dependency>
			<groupId>com.taotaogroupId>
			<artifactId>taotao-manager-mapperartifactId>
			<version>0.0.1-SNAPSHOTversion>
		dependency>
		
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-contextartifactId>
		dependency>
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-beansartifactId>
		dependency>
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-webmvcartifactId>
		dependency>
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-jdbcartifactId>
		dependency>
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-aspectsartifactId>
		dependency>
	dependencies>
project>

        2.5.4 创建taotao-manager-web

maven实现多模块项目整合_第13张图片
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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0modelVersion>
	<parent>
		<groupId>com.taotaogroupId>
		<artifactId>taotao-managerartifactId>
		<version>0.0.1-SNAPSHOTversion>
	parent>
	<artifactId>taotao-manager-webartifactId>
	<packaging>warpackaging>
	
	<dependencies>
		<dependency>
			<groupId>com.taotaogroupId>
			<artifactId>taotao-manager-serviceartifactId>
			<version>0.0.1-SNAPSHOTversion>
		dependency>
		
		<dependency>
			<groupId>jstlgroupId>
			<artifactId>jstlartifactId>
		dependency>
		<dependency>
			<groupId>javax.servletgroupId>
			<artifactId>servlet-apiartifactId>
			<scope>providedscope>
		dependency>
		<dependency>
			<groupId>javax.servletgroupId>
			<artifactId>jsp-apiartifactId>
			<scope>providedscope>
		dependency>
		
		<dependency>
			<groupId>commons-fileuploadgroupId>
			<artifactId>commons-fileuploadartifactId>
		dependency>
	dependencies>
	
	<build>
		<resources>
			
		    <resource>
		        <directory>src/main/resourcesdirectory>
		        <includes>
		            <include>**/*.propertiesinclude>
		            <include>**/*.xmlinclude>
		        includes>
		        <filtering>falsefiltering>
		    resource>
		resources>
	build>
project>

解决红叉,没有web.xml问题
maven实现多模块项目整合_第14张图片

        2.6 在taotao-manager中添加Tomcat插件

                        pom文件中添加的内容为:


		
		
			
				org.apache.tomcat.maven
				tomcat7-maven-plugin
				
					8080
					/
				
			
		
	

maven实现多模块项目整合_第15张图片

        2.7 在taotao-manager-web中新建index.jsp文件

        2.8 运行工程

                  要运行工程,需要运行聚合工程也就是taotao-manager。
maven实现多模块项目整合_第16张图片maven实现多模块项目整合_第17张图片

2.9 测试连接数据库(在manager-web模块下)

public class TestConnectMysql {
	@Test
	public void Test() {
		ApplicationContext applicationContext = 
				new ClassPathXmlApplicationContext("classpath:spring/applicationContext-dao.xml");
		DataSource dataSource = (DataSource) applicationContext.getBean("dataSource");
		Connection connection;
		try {
			connection = dataSource.getConnection();
			System.out.println(connection);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}

        2.10 taotao-manage子模块依赖关系

maven实现多模块项目整合_第18张图片
依赖关系:
web --> service
service --> mapper
mapper --> pojo

PS:个人学习记录

你可能感兴趣的:(学习记录)