Eclipse创建Maven聚合项目
整体架构图
1.新建父工程
新建maven父项目(用来管理jar包版本),使子系统使用同一个版本的jar包。
File-》New-》Other-》Maven Project,打包方式选pom
- <!-- 集中定义依赖版本号 -->
- <properties>
- <activemq.version>5.11.2</activemq.version>
- <freemarker.version>2.3.23</freemarker.version>
- <quartz.version>2.2.2</quartz.version>
- </properties>
- <!-- dependencyManagement管理包的版本,并没有添加依赖 -->
- <dependencyManagement>
- <dependencies>
- <!-- 时间操作组件 -->
- <dependency>
- <groupId>joda-time</groupId>
- <artifactId>joda-time</artifactId>
- <version>${joda-time.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
- <build>
- <finalName>${project.artifactId}</finalName>
- <plugins>
- <!-- 资源文件拷贝插件 -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <version>2.7</version>
- <configuration>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- <!-- java编译插件 -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.2</version>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- </plugins>
- <!-- 插件管理,此处并没有使用,子项目中build -->
- <pluginManagement>
- <plugins>
- <!-- 配置Tomcat插件 -->
- <plugin>
- <groupId>org.apache.tomcat.maven</groupId>
- <artifactId>tomcat7-maven-plugin</artifactId>
- <version>2.2</version>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
2.新建子工具工程
创建common通用工具类项目,父类为刚才创建的项目,打包方式为jar
- <parent>
- <groupId>cn.e3mall</groupId>
- <artifactId>e3-parent</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- </parent>
- <groupId>cn.e3mall</groupId>
- <artifactId>e3-common</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <!-- 依赖的jar包 -->
- <dependencies>
- <!-- Jackson Json处理工具包 -->
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- </dependency>
- <!-- httpclient -->
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- </dependency>
- <!-- 单元测试 -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <!-- 日志处理 -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </dependency>
- </dependencies>
3.新建服务工程(POM)
创建聚合项目,聚合pojo、dao、interface、service等子项目。打包方式为pom,父项目为刚才创建的jar包版本管理项目。
- <parent>
- <groupId>cn.e3mall</groupId>
- <artifactId>e3-parent</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- </parent>
- <groupId>cn.e3mall</groupId>
- <artifactId>e3-manager</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>pom</packaging>
- <dependencies>
- <!--依赖e3-common通用工具类工程 -->
- <dependency>
- <groupId>cn.e3mall</groupId>
- <artifactId>e3-common</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- </dependency>
- </dependencies>
- <!-- e3-manager是聚合工程,聚合pojo、dao、service等子项目 -->
- <modules>
- <module>e3-manager-pojo</module>
- <module>e3-manager-dao</module>
- <module>e3-manager-interface</module>
- <module>e3-manager-service</module>
- <module>e3-manager-web</module>
- </modules>
- <!-- 配置tomcat插件 -->
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.tomcat.maven</groupId>
- <artifactId>tomcat7-maven-plugin</artifactId>
- <version>2.2</version>
- <configuration>
- <path>/</path> <!-- tomcat项目路径 -->
- <port>8080</port> <!-- tomcat端口 -->
- </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.e3mall</groupId>
- <artifactId>e3-manager-pojo</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- </dependency>
- <!-- Mybatis -->
- <dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis</artifactId>
- </dependency>
- <dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis-spring</artifactId>
- </dependency>
- <dependency>
- <groupId>com.github.miemiedev</groupId>
- <artifactId>mybatis-paginator</artifactId>
- </dependency>
- <dependency>
- <groupId>com.github.pagehelper</groupId>
- <artifactId>pagehelper</artifactId>
- </dependency>
- <!-- MySql -->
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- </dependency>
- <!-- 连接池 -->
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>druid</artifactId>
- </dependency>
- </dependencies>
- <!-- 如果不添加此节点mybatis的mapper.xml以及db.properties文件都会被漏掉。 -->
- <build>
- <resources>
- <resource>
- <directory>src/main/java</directory>
- <includes>
- <include>**/*.properties</include>
- <include>**/*.xml</include>
- </includes>
- <filtering>false</filtering>
- </resource>
- </resources>
- </build>
6.右击manager聚合项目Run as-》Maven build-》clean tomcat7:run
7.如果发现执行失败,且maven仓库中找不到父项目和common项目,此时需要右击这两个项目Run as-》Maven Install即可加载到本地仓库中。
8.执行成功,浏览器输入地址即可查看