maven多项目配置(maven-分布式项目之工程结构配置)

maven的作用

1.管理jar包及依赖、工程之间的依赖

2.项目构建。

3.工程聚合、继承、依赖

Maven的工程类型

1.war包工程

2.Jar包工程

3.pom工程

后台管理系统工程结构:

taotao-parent (pom)-- 管理依赖jar包的版本,全局,公司级别

|--taotao-common (jar)--- 通用组件、工具类

|--taotao-manage (pom)-- 后台系统

|--com.taotao.manage.web(war)

|--com.taotao.manage.service(jar)

|--com.taotao.manage.mapper(jar)

|--com.taotao.manage.pojo(jar)

1.创建taotao-parent父工程

1.new a maven project

2.Create a simple project

3.Packaging选择pom(聚合项目)

4.修改pom.xml

[html] view plain copy

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.taotao</groupId>
  5. <artifactId>taotao-parent</artifactId>
  6. <version>0.0.1-SNAPSHOT</version>
  7. <packaging>pom</packaging>
  8. <!-- 集中定义依赖版本号 -->
  9. <properties>
  10. <junit.version>4.12</junit.version>
  11. <spring.version>4.1.3.RELEASE</spring.version>
  12. <mybatis.version>3.2.8</mybatis.version>
  13. <mybatis.spring.version>1.2.2</mybatis.spring.version>
  14. <mybatis.paginator.version>1.2.15</mybatis.paginator.version>
  15. <mysql.version>5.1.32</mysql.version>
  16. <slf4j.version>1.6.4</slf4j.version>
  17. <jackson.version>2.4.2</jackson.version>
  18. <druid.version>1.0.9</druid.version>
  19. <httpclient.version>4.3.5</httpclient.version>
  20. <jstl.version>1.2</jstl.version>
  21. <servlet-api.version>2.5</servlet-api.version>
  22. <jsp-api.version>2.0</jsp-api.version>
  23. <joda-time.version>2.5</joda-time.version>
  24. <commons-lang3.version>3.3.2</commons-lang3.version>
  25. <commons-io.version>1.3.2</commons-io.version>
  26. <commons-net.version>3.3</commons-net.version>
  27. <pagehelper.version>3.4.2-fix</pagehelper.version>
  28. <jsqlparser.version>0.9.1</jsqlparser.version>
  29. <commons-fileupload.version>1.3.1</commons-fileupload.version>
  30. <jedis.version>2.7.2</jedis.version>
  31. <solrj.version>4.10.3</solrj.version>
  32. </properties>
  33. <dependencyManagement>
  34. <dependencies>
  35. <!-- 时间操作组件 -->
  36. <dependency>
  37. <groupId>joda-time</groupId>
  38. <artifactId>joda-time</artifactId>
  39. <version>${joda-time.version}</version>
  40. </dependency>
  41. <!-- Apache工具组件 -->
  42. <dependency>
  43. <groupId>org.apache.commons</groupId>
  44. <artifactId>commons-lang3</artifactId>
  45. <version>${commons-lang3.version}</version>
  46. </dependency>
  47. <dependency>
  48. <groupId>org.apache.commons</groupId>
  49. <artifactId>commons-io</artifactId>
  50. <version>${commons-io.version}</version>
  51. </dependency>
  52. <dependency>
  53. <groupId>commons-net</groupId>
  54. <artifactId>commons-net</artifactId>
  55. <version>${commons-net.version}</version>
  56. </dependency>
  57. <!-- Jackson Json处理工具包 -->
  58. <dependency>
  59. <groupId>com.fasterxml.jackson.core</groupId>
  60. <artifactId>jackson-databind</artifactId>
  61. <version>${jackson.version}</version>
  62. </dependency>
  63. <!-- httpclient -->
  64. <dependency>
  65. <groupId>org.apache.httpcomponents</groupId>
  66. <artifactId>httpclient</artifactId>
  67. <version>${httpclient.version}</version>
  68. </dependency>
  69. <!-- 单元测试 -->
  70. <dependency>
  71. <groupId>junit</groupId>
  72. <artifactId>junit</artifactId>
  73. <version>${junit.version}</version>
  74. <scope>test</scope>
  75. </dependency>
  76. <!-- 日志处理 -->
  77. <dependency>
  78. <groupId>org.slf4j</groupId>
  79. <artifactId>slf4j-log4j12</artifactId>
  80. <version>${slf4j.version}</version>
  81. </dependency>
  82. <!-- Mybatis -->
  83. <dependency>
  84. <groupId>org.mybatis</groupId>
  85. <artifactId>mybatis</artifactId>
  86. <version>${mybatis.version}</version>
  87. </dependency>
  88. <dependency>
  89. <groupId>org.mybatis</groupId>
  90. <artifactId>mybatis-spring</artifactId>
  91. <version>${mybatis.spring.version}</version>
  92. </dependency>
  93. <dependency>
  94. <groupId>com.github.miemiedev</groupId>
  95. <artifactId>mybatis-paginator</artifactId>
  96. <version>${mybatis.paginator.version}</version>
  97. </dependency>
  98. <dependency>
  99. <groupId>com.github.pagehelper</groupId>
  100. <artifactId>pagehelper</artifactId>
  101. <version>${pagehelper.version}</version>
  102. </dependency>
  103. <!-- MySql -->
  104. <dependency>
  105. <groupId>mysql</groupId>
  106. <artifactId>mysql-connector-java</artifactId>
  107. <version>${mysql.version}</version>
  108. </dependency>
  109. <!-- 连接池 -->
  110. <dependency>
  111. <groupId>com.alibaba</groupId>
  112. <artifactId>druid</artifactId>
  113. <version>${druid.version}</version>
  114. </dependency>
  115. <!-- Spring -->
  116. <dependency>
  117. <groupId>org.springframework</groupId>
  118. <artifactId>spring-context</artifactId>
  119. <version>${spring.version}</version>
  120. </dependency>
  121. <dependency>
  122. <groupId>org.springframework</groupId>
  123. <artifactId>spring-beans</artifactId>
  124. <version>${spring.version}</version>
  125. </dependency>
  126. <dependency>
  127. <groupId>org.springframework</groupId>
  128. <artifactId>spring-webmvc</artifactId>
  129. <version>${spring.version}</version>
  130. </dependency>
  131. <dependency>
  132. <groupId>org.springframework</groupId>
  133. <artifactId>spring-jdbc</artifactId>
  134. <version>${spring.version}</version>
  135. </dependency>
  136. <dependency>
  137. <groupId>org.springframework</groupId>
  138. <artifactId>spring-aspects</artifactId>
  139. <version>${spring.version}</version>
  140. </dependency>
  141. <!-- JSP相关 -->
  142. <dependency>
  143. <groupId>jstl</groupId>
  144. <artifactId>jstl</artifactId>
  145. <version>${jstl.version}</version>
  146. </dependency>
  147. <dependency>
  148. <groupId>javax.servlet</groupId>
  149. <artifactId>servlet-api</artifactId>
  150. <version>${servlet-api.version}</version>
  151. <scope>provided</scope>
  152. </dependency>
  153. <dependency>
  154. <groupId>javax.servlet</groupId>
  155. <artifactId>jsp-api</artifactId>
  156. <version>${jsp-api.version}</version>
  157. <scope>provided</scope>
  158. </dependency>
  159. <!-- 文件上传组件 -->
  160. <dependency>
  161. <groupId>commons-fileupload</groupId>
  162. <artifactId>commons-fileupload</artifactId>
  163. <version>${commons-fileupload.version}</version>
  164. </dependency>
  165. <!-- Redis客户端 -->
  166. <dependency>
  167. <groupId>redis.clients</groupId>
  168. <artifactId>jedis</artifactId>
  169. <version>${jedis.version}</version>
  170. </dependency>
  171. <!-- solr客户端 -->
  172. <dependency>
  173. <groupId>org.apache.solr</groupId>
  174. <artifactId>solr-solrj</artifactId>
  175. <version>${solrj.version}</version>
  176. </dependency>
  177. </dependencies>
  178. </dependencyManagement>
  179. <build>
  180. <finalName>${project.artifactId}</finalName>
  181. <plugins>
  182. <!-- 资源文件拷贝插件 -->
  183. <plugin>
  184. <groupId>org.apache.maven.plugins</groupId>
  185. <artifactId>maven-resources-plugin</artifactId>
  186. <version>2.7</version>
  187. <configuration>
  188. <encoding>UTF-8</encoding>
  189. </configuration>
  190. </plugin>
  191. <!-- java编译插件 -->
  192. <plugin>
  193. <groupId>org.apache.maven.plugins</groupId>
  194. <artifactId>maven-compiler-plugin</artifactId>
  195. <version>3.2</version>
  196. <configuration>
  197. <source>1.7</source>
  198. <target>1.7</target>
  199. <encoding>UTF-8</encoding>
  200. </configuration>
  201. </plugin>
  202. </plugins>
  203. <pluginManagement>
  204. <plugins>
  205. <!-- 配置Tomcat插件 -->
  206. <plugin>
  207. <groupId>org.apache.tomcat.maven</groupId>
  208. <artifactId>tomcat7-maven-plugin</artifactId>
  209. <version>2.2</version>
  210. <configuration>
  211. <path>/</path>
  212. <port>8888</port>
  213. <charset>utf-8</charset>
  214. <uriEncoding>UTF-8</uriEncoding>
  215. </configuration>
  216. </plugin>
  217. </plugins>
  218. </pluginManagement>
  219. </build>
  220. </project>

5.maven install 打包到本地仓库

4.创建taotao-manager-pojo模块

1.右键taotao-manager---new Maven Module

2.Create a simple project

3.Packaging选择jar(被其他工程所引用)

4.Group id与taotao-parent的Group id一致(同一组织)

5.pom文件不需要修改,不依赖任何jar包

5.创建taotao-manager-mapper

1.右键taotao-manager---new Maven Module

2.Create a simple project

3.Packaging选择jar(被其他工程所引用)

4.Group id与taotao-parent的Group id一致(同一组织)

5.pom文件修改(依赖taotao-manager-pojo)。及添加mybatis、分页插件、数据库连接池、mysql连接依赖

maven多项目配置(maven-分布式项目之工程结构配置)(1)

6.创建taotao-manager-service

1.右键taotao-manager---new Maven Module

2.Create a simple project

3.Packaging选择jar(被其他工程所引用)

4.Group id与taotao-parent的Group id一致(同一组织)

5.pom文件修改(依赖taotao-manager-mapper)。及添加spring相关依赖

maven多项目配置(maven-分布式项目之工程结构配置)(2)

7.创建taotao-manager-web

1.右键taotao-manager---new Maven Module

2.Create a simple project

3.Packaging选择war

4.Group id与taotao-parent的Group id一致(同一组织)

5.pom文件修改(依赖taotao-manager-service)。及添加jstl、jsp、servlet、commons-fileupload等依赖

maven多项目配置(maven-分布式项目之工程结构配置)(3)

6.在webapp下创建WEB-INF,继续创建web.xml

[html] view plain copy

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  5. id="taotao" version="2.5">
  6. <display-name>taotao-manager</display-name>
  7. <welcome-file-list>
  8. <welcome-file>index.html</welcome-file>
  9. <welcome-file>index.htm</welcome-file>
  10. <welcome-file>index.jsp</welcome-file>
  11. <welcome-file>default.html</welcome-file>
  12. <welcome-file>default.htm</welcome-file>
  13. <welcome-file>default.jsp</welcome-file>
  14. </welcome-file-list>
  15. </web-app>
运行测试

要运行工程,需要运行聚合工程也就是taotao-manager。

1.在taotao-manager工程的pom文件中添加如下内容:

[html] view plain copy

  1. <build>
  2. <!-- 配置插件 -->
  3. <plugins>
  4. <plugin>
  5. <groupId>org.apache.tomcat.maven</groupId>
  6. <artifactId>tomcat7-maven-plugin</artifactId>
  7. <configuration>
  8. <port>8080</port>
  9. <path>/</path>
  10. </configuration>
  11. </plugin>
  12. </plugins>
  13. </build>

2.使用maven命令:

clean tomcat7:run

注意:

(1)需要把taotao-parent工程安装到本地仓库。Install

(2)需要把taotao-common安装到本地仓库。

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页