整体架构图
1.新建父工程
新建maven父项目(用来管理jar包版本),使子系统使用同一个版本的jar包。
File-》New-》Other-》Maven Project,打包方式选pom
<properties> <activemq.version>5.11.2activemq.version> <freemarker.version>2.3.23freemarker.version> <quartz.version>2.2.2quartz.version> properties> <dependencyManagement> <dependencies> <dependency> <groupId>joda-timegroupId> <artifactId>joda-timeartifactId> <version>${joda-time.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>
2.新建子工具工程
创建common通用工具类项目,父类为刚才创建的项目,打包方式为jar
<parent> <groupId>cn.e3mallgroupId> <artifactId>e3-parentartifactId> <version>0.0.1-SNAPSHOTversion> parent> <groupId>cn.e3mallgroupId> <artifactId>e3-commonartifactId> <version>0.0.1-SNAPSHOTversion> <dependencies> <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>
3.新建服务工程(POM)
创建聚合项目,聚合pojo、dao、interface、service等子项目。打包方式为pom,父项目为刚才创建的jar包版本管理项目。
<parent> <groupId>cn.e3mallgroupId> <artifactId>e3-parentartifactId> <version>0.0.1-SNAPSHOTversion> parent> <groupId>cn.e3mallgroupId> <artifactId>e3-managerartifactId> <version>0.0.1-SNAPSHOTversion> <packaging>pompackaging> <dependencies> <dependency> <groupId>cn.e3mallgroupId> <artifactId>e3-commonartifactId> <version>0.0.1-SNAPSHOTversion> dependency> dependencies> <modules> <module>e3-manager-pojomodule> <module>e3-manager-daomodule> <module>e3-manager-interfacemodule> <module>e3-manager-servicemodule> <module>e3-manager-webmodule> modules> <build> <plugins> <plugin> <groupId>org.apache.tomcat.mavengroupId> <artifactId>tomcat7-maven-pluginartifactId> <version>2.2version> <configuration> <path>/path> <port>8080port> configuration> plugin> plugins> build>
4.创建服务层的子项目
右击步骤3创建的聚合项目,选择Maven Module,输入Module项目创建子项目,next选择jar打包方式,用相同的方法创建pojo、dao、interface、service、web(这个打包方式选择war)子项目。
5.子项目依赖关系
dao和interface依赖pojo,service依赖dao和interface,web依赖service。
其中dao的pom文件为
<dependencies> <dependency> <groupId>cn.e3mallgroupId> <artifactId>e3-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>
6.右击manager聚合项目Run as-》Maven build-》clean tomcat7:run
7.如果发现执行失败,且maven仓库中找不到父项目和common项目,此时需要右击这两个项目Run as-》Maven Install即可加载到本地仓库中。
8.执行成功,浏览器输入地址即可查看