Idea多模块工程创建——继承、聚合

一、工程介绍

淘淘网上商城是一个综合性的B2C平台,类似京东商城、天猫商城。会员可以在商城浏览商品、下订单,以及参加各种活动。
管理员、运营可以在平台后台管理系统中管理商品、订单、会员等。
客服可以在后台管理系统中处理用户的询问以及投诉。

具体实现:

二、工程目录

taotao-parent(父工程管理jar包的版本)

   |-taotao-common(把通用的工具类打包)

   |-taotao-manager(继承父工程)

      |-taotao-manager-pojo

      |-taotao-manager-dao

      |-taotao-manager-service

      |-taotao-manager-web(war包)

taotao-parent 为项目的父工程,用来管理jar包及版本

taotao-common为通用工程,继承父工程,就是把通用的工具类打包

taotao-manager为开发工程,同样继承父工程

其中,taotao-manager-pojo,taotao-manager-dao,taotao-manager-service和
taotao-manager-web均为开发工程的一个子模块,依赖于开发工程taotao-manager

前3个子模块打成jar包,taotao-manager-web打成war包

三、创建工程

1. 创建taotao-parent父类工程,后面所有的工程全部继承该工程
File → New → Project

Maven → Next

创建完后,删除生成的src目录,修改打包方式为pom,taotao-parent:pom.xml

maven中有3种工程:
    1、pom工程:用在父级或聚合工程中,用来做jar包的版本控制。
    2、war工程:会打包成war,发布在服务器上。如网站或服务。
    3、jar工程:打包成jar用作jar包使用。

 

  1 <?xml version="1.0" encoding="UTF-8"?>
  2 <project xmlns="http://maven.apache.org/POM/4.0.0"
  3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5     <modelVersion>4.0.0</modelVersion>
  6     <!--功能:父工程,打包方式为pom,管理jar包的版本号。项目中的所有工程都应该继承父工程-->
  7     <!--包含项目中用到的所有jar包版本-->
  8     <groupId>com.taotao</groupId>
  9     <artifactId>taotao-parent</artifactId>
 10     <packaging>pom</packaging>
 11     <version>1.0-SNAPSHOT</version>
 12     <!--里面的module自动生成,当下面工程比如taotao-commom手动删除时,module不会自动就删除,还得手动删除-->
 13     <modules>
 14         <module>../taotao-common</module>
 15         <module>../taotao-manager</module>
 16     </modules>
 17 
 18     <!-- 集中定义依赖版本号 -->
 19     <properties>
 20         <junit.version>4.12</junit.version>
 21         <spring.version>4.1.3.RELEASE</spring.version>
 22         <mybatis.version>3.2.8</mybatis.version>
 23         <mybatis.spring.version>1.2.2</mybatis.spring.version>
 24         <mybatis.paginator.version>1.2.15</mybatis.paginator.version>
 25         <mysql.version>5.1.32</mysql.version>
 26         <slf4j.version>1.6.6</slf4j.version>
 27         <jackson.version>2.4.2</jackson.version>
 28         <druid.version>1.0.9</druid.version>
 29         <httpclient.version>4.3.5</httpclient.version>
 30         <jstl.version>1.2</jstl.version>
 31         <servlet-api.version>2.5</servlet-api.version>
 32         <jsp-api.version>2.0</jsp-api.version>
 33         <joda-time.version>2.5</joda-time.version>
 34         <commons-lang3.version>3.3.2</commons-lang3.version>
 35         <commons-io.version>1.3.2</commons-io.version>
 36         <commons-net.version>3.3</commons-net.version>
 37         <pagehelper.version>3.4.2</pagehelper.version>
 38         <jsqlparser.version>0.9.1</jsqlparser.version>
 39         <commons-fileupload.version>1.3.1</commons-fileupload.version>
 40         <jedis.version>2.7.2</jedis.version>
 41         <solrj.version>4.10.3</solrj.version>
 42         <freemarker.version>2.3.23</freemarker.version>
 43         <quartz.version>2.2.2</quartz.version>
 44     </properties>
 45 
 46     <dependencyManagement>
 47         <dependencies>
 48             <!-- 时间操作组件 -->
 49             <dependency>
 50                 <groupId>joda-time</groupId>
 51                 <artifactId>joda-time</artifactId>
 52                 <version>${joda-time.version}</version>
 53             </dependency>
 54             <!-- Apache工具组件 -->
 55             <dependency>
 56                 <groupId>org.apache.commons</groupId>
 57                 <artifactId>commons-lang3</artifactId>
 58                 <version>${commons-lang3.version}</version>
 59             </dependency>
 60             <dependency>
 61                 <groupId>org.apache.commons</groupId>
 62                 <artifactId>commons-io</artifactId>
 63                 <version>${commons-io.version}</version>
 64             </dependency>
 65             <dependency>
 66                 <groupId>commons-net</groupId>
 67                 <artifactId>commons-net</artifactId>
 68                 <version>${commons-net.version}</version>
 69             </dependency>
 70             <!-- Jackson Json处理工具包 -->
 71             <dependency>
 72                 <groupId>com.fasterxml.jackson.core</groupId>
 73                 <artifactId>jackson-databind</artifactId>
 74                 <version>${jackson.version}</version>
 75             </dependency>
 76             <!-- httpclient -->
 77             <dependency>
 78                 <groupId>org.apache.httpcomponents</groupId>
 79                 <artifactId>httpclient</artifactId>
 80                 <version>${httpclient.version}</version>
 81             </dependency>
 82             <!-- 单元测试 -->
 83             <dependency>
 84                 <groupId>junit</groupId>
 85                 <artifactId>junit</artifactId>
 86                 <version>${junit.version}</version>
 87                 <scope>test</scope>
 88             </dependency>
 89             <!-- 日志处理 -->
 90             <dependency>
 91                 <groupId>org.slf4j</groupId>
 92                 <artifactId>slf4j-log4j12</artifactId>
 93                 <version>${slf4j.version}</version>
 94             </dependency>
 95             <!-- Mybatis -->
 96             <dependency>
 97                 <groupId>org.mybatis</groupId>
 98                 <artifactId>mybatis</artifactId>
 99                 <version>${mybatis.version}</version>
100             </dependency>
101             <dependency>
102                 <groupId>org.mybatis</groupId>
103                 <artifactId>mybatis-spring</artifactId>
104                 <version>${mybatis.spring.version}</version>
105             </dependency>
106             <dependency>
107                 <groupId>com.github.miemiedev</groupId>
108                 <artifactId>mybatis-paginator</artifactId>
109                 <version>${mybatis.paginator.version}</version>
110             </dependency>
111             <dependency>
112                 <groupId>com.github.pagehelper</groupId>
113                 <artifactId>pagehelper</artifactId>
114                 <version>${pagehelper.version}</version>
115             </dependency>
116             <!-- MySql -->
117             <dependency>
118                 <groupId>mysql</groupId>
119                 <artifactId>mysql-connector-java</artifactId>
120                 <version>${mysql.version}</version>
121             </dependency>
122             <!-- 连接池 -->
123             <dependency>
124                 <groupId>com.alibaba</groupId>
125                 <artifactId>druid</artifactId>
126                 <version>${druid.version}</version>
127             </dependency>
128             <!-- Spring -->
129             <dependency>
130                 <groupId>org.springframework</groupId>
131                 <artifactId>spring-context</artifactId>
132                 <version>${spring.version}</version>
133             </dependency>
134             <dependency>
135                 <groupId>org.springframework</groupId>
136                 <artifactId>spring-beans</artifactId>
137                 <version>${spring.version}</version>
138             </dependency>
139             <dependency>
140                 <groupId>org.springframework</groupId>
141                 <artifactId>spring-webmvc</artifactId>
142                 <version>${spring.version}</version>
143             </dependency>
144             <dependency>
145                 <groupId>org.springframework</groupId>
146                 <artifactId>spring-jdbc</artifactId>
147                 <version>${spring.version}</version>
148             </dependency>
149             <dependency>
150                 <groupId>org.springframework</groupId>
151                 <artifactId>spring-aspects</artifactId>
152                 <version>${spring.version}</version>
153             </dependency>
154             <dependency>
155                 <groupId>org.springframework</groupId>
156                 <artifactId>spring-context-support</artifactId>
157                 <version>${spring.version}</version>
158             </dependency>
159             <!-- JSP相关 -->
160             <dependency>
161                 <groupId>jstl</groupId>
162                 <artifactId>jstl</artifactId>
163                 <version>${jstl.version}</version>
164             </dependency>
165             <dependency>
166                 <groupId>javax.servlet</groupId>
167                 <artifactId>servlet-api</artifactId>
168                 <version>${servlet-api.version}</version>
169                 <scope>provided</scope>
170             </dependency>
171             <dependency>
172                 <groupId>javax.servlet</groupId>
173                 <artifactId>jsp-api</artifactId>
174                 <version>${jsp-api.version}</version>
175                 <scope>provided</scope>
176             </dependency>
177             <!-- 文件上传组件 -->
178             <dependency>
179                 <groupId>commons-fileupload</groupId>
180                 <artifactId>commons-fileupload</artifactId>
181                 <version>${commons-fileupload.version}</version>
182             </dependency>
183             <!-- Redis客户端 -->
184             <dependency>
185                 <groupId>redis.clients</groupId>
186                 <artifactId>jedis</artifactId>
187                 <version>${jedis.version}</version>
188             </dependency>
189             <!-- solr客户端 -->
190             <dependency>
191                 <groupId>org.apache.solr</groupId>
192                 <artifactId>solr-solrj</artifactId>
193                 <version>${solrj.version}</version>
194             </dependency>
195             <dependency>
196                 <groupId>org.freemarker</groupId>
197                 <artifactId>freemarker</artifactId>
198                 <version>${freemarker.version}</version>
199             </dependency>
200             <!-- quartz任务调度框架 -->
201             <dependency>
202                 <groupId>org.quartz-scheduler</groupId>
203                 <artifactId>quartz</artifactId>
204                 <version>${quartz.version}</version>
205             </dependency>
206         </dependencies>
207     </dependencyManagement>
208 
209     <build>
210         <finalName>${project.artifactId}</finalName>
211         <resources>
212             <resource>
213                 <directory>src/main/java</directory>
214                 <includes>
215                     <include>**/*.xml</include>
216                 </includes>
217                 <filtering>true</filtering>
218             </resource>
219             <resource>
220                 <directory>src/main/resources</directory>
221             </resource>
222         </resources>
223         <plugins>
224             <!-- 资源文件拷贝插件 -->
225             <plugin>
226                 <groupId>org.apache.maven.plugins</groupId>
227                 <artifactId>maven-resources-plugin</artifactId>
228                 <version>2.7</version>
229                 <configuration>
230                     <encoding>UTF-8</encoding>
231                 </configuration>
232             </plugin>
233             <!-- java编译插件 -->
234             <plugin>
235                 <groupId>org.apache.maven.plugins</groupId>
236                 <artifactId>maven-compiler-plugin</artifactId>
237                 <version>3.7.0</version>
238                 <configuration>
239                     <source>1.8</source>
240                     <target>1.8</target>
241                     <encoding>UTF-8</encoding>
242                 </configuration>
243             </plugin>
244         </plugins>
245         <pluginManagement>
246             <plugins>
247                 <!-- 配置Tomcat插件 -->
248                 <plugin>
249                     <groupId>org.apache.tomcat.maven</groupId>
250                     <artifactId>tomcat7-maven-plugin</artifactId>
251                     <version>2.2</version>
252                 </plugin>
253             </plugins>
254         </pluginManagement>
255     </build>
256 </project>

2. 创建通用工程taotao-common,继承父工程,保存的是通用的工具类及pojo,打包方式jar包
taotao-parent文件上右击创建新的model,和创建maven类似不需要勾选信息,taotao-parent→ New → Module

注意:因为common 与 parent 只有继承、但没有聚合的关系,所以在新建common项目的时候 Add as module to 要设置为 null。manager同理。

然后会出现如下如下界面:

修改打包方式为jar,taotao-common:pom.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <parent>
 6         <artifactId>taotao-parent</artifactId>
 7         <groupId>com.taotao</groupId>
 8         <version>1.0-SNAPSHOT</version>
 9         <relativePath>../taotao-parent/pom.xml</relativePath>
10     </parent>
11     <modelVersion>4.0.0</modelVersion>
12     <!--功能:通用的工具类,通用的pojo 打包方式jar-->
13     <!--继承parent工程-->
14     <artifactId>taotao-common</artifactId>
15     <dependencies>
16         <!--====================添加工具类包的依赖=======================-->
17         <!-- 时间操作组件 -->
18         <dependency>
19             <groupId>joda-time</groupId>
20             <artifactId>joda-time</artifactId>
21         </dependency>
22         <!-- Apache工具组件 -->
23         <dependency>
24             <groupId>org.apache.commons</groupId>
25             <artifactId>commons-lang3</artifactId>
26         </dependency>
27         <dependency>
28             <groupId>org.apache.commons</groupId>
29             <artifactId>commons-io</artifactId>
30         </dependency>
31         <dependency>
32             <groupId>commons-net</groupId>
33             <artifactId>commons-net</artifactId>
34         </dependency>
35         <!-- Jackson Json处理工具包 -->
36         <dependency>
37             <groupId>com.fasterxml.jackson.core</groupId>
38             <artifactId>jackson-databind</artifactId>
39         </dependency>
40         <!-- httpclient -->
41         <dependency>
42             <groupId>org.apache.httpcomponents</groupId>
43             <artifactId>httpclient</artifactId>
44         </dependency>
45         <!-- 单元测试 -->
46         <dependency>
47             <groupId>junit</groupId>
48             <artifactId>junit</artifactId>
49         </dependency>
50         <!-- 日志处理 -->
51         <dependency>
52             <groupId>org.slf4j</groupId>
53             <artifactId>slf4j-log4j12</artifactId>
54         </dependency>
55     </dependencies>
56 </project>

3. 创建taotao-manager聚合工程,打包方式pom,里面有一堆模块。创建工程类似taotao-common的过程,在taotao-parent文件上右击创建新的model,和创建maven类似不需要勾选信息:taotao-parent→ New → Module → Next → taotao-manager

taotao-manager:pom.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <parent>
 6         <artifactId>taotao-parent</artifactId>
 7         <groupId>com.taotao</groupId>
 8         <version>1.0-SNAPSHOT</version>
 9         <relativePath>../taotao-parent/pom.xml</relativePath>
10     </parent>
11     <modelVersion>4.0.0</modelVersion>
12 
13     <artifactId>taotao-manager</artifactId>
14     <packaging>pom</packaging>
15     <modules>
16         <module>taotao-manager-pojo</module>
17         <module>taotao-manager-dao</module>
18         <module>taotao-manager-service</module>
19         <module>taotao-manager-web</module>
20     </modules>
21 
22     <dependencies>
23         <!--工程之间的依赖 manager依赖common-->
24         <dependency>
25             <groupId>com.taotao</groupId>
26             <artifactId>taotao-common</artifactId>
27             <version>1.0-SNAPSHOT</version>
28         </dependency>
29     </dependencies>
30 
31     <build>
32         <!--配置插件-->
33         <plugins>
34             <plugin>
35                 <groupId>org.apache.tomcat.maven</groupId>
36                 <artifactId>tomcat7-maven-plugin</artifactId>
37                 <configuration>
38                     <port>8086</port>
39                     <path>/</path>
40                 </configuration>
41             </plugin>
42         </plugins>
43     </build>
44 </project>

3.1 添加模块,打包方式都为jar,taotao-manager-pojo,taotao-manager-dao,taotao-manager-service创建方式一样

taotao-manager-pojo

在taotao-manager上右键New → Module → Next → taotao-manager-pojo,过程类似mall-common的创建但是路径选择需要重写填写,如下图:

taotao-manager-pojo:pom.xml pojo不需要依赖其它jar包

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <parent>
 6         <artifactId>taotao-manager</artifactId>
 7         <groupId>com.taotao</groupId>
 8         <version>1.0-SNAPSHOT</version>
 9     </parent>
10     <modelVersion>4.0.0</modelVersion>
11 
12     <artifactId>taotao-manager-pojo</artifactId>
13 </project>

taotao-manager-dao:pom.xml dao的运行需要Mybatis等的支持,所以要添加依赖

 
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <parent>
 6         <artifactId>taotao-manager</artifactId>
 7         <groupId>com.taotao</groupId>
 8         <version>1.0-SNAPSHOT</version>
 9     </parent>
10     <modelVersion>4.0.0</modelVersion>
11 
12     <artifactId>taotao-manager-dao</artifactId>
13 
14     <dependencies>
15         <!--依赖pojo-->
16         <dependency>
17             <artifactId>taotao-manager-pojo</artifactId>
18             <groupId>com.taotao</groupId>
19             <version>1.0-SNAPSHOT</version>
20         </dependency>
21 
22         <!--====================添加mybatis等数据库相关依赖===========================-->
23         <dependency>
24             <groupId>org.mybatis</groupId>
25             <artifactId>mybatis</artifactId>
26         </dependency>
27         <dependency>
28             <groupId>org.mybatis</groupId>
29             <artifactId>mybatis-spring</artifactId>
30         </dependency>
31         <dependency>
32             <groupId>com.github.miemiedev</groupId>
33             <artifactId>mybatis-paginator</artifactId>
34         </dependency>
35         <dependency>
36             <groupId>com.github.pagehelper</groupId>
37             <artifactId>pagehelper</artifactId>
38         </dependency>
39         <!-- MySql -->
40         <dependency>
41             <groupId>mysql</groupId>
42             <artifactId>mysql-connector-java</artifactId>
43         </dependency>
44         <!-- 连接池 -->
45         <dependency>
46             <groupId>com.alibaba</groupId>
47             <artifactId>druid</artifactId>
48         </dependency>
49     </dependencies>
50 </project>

taotao-manager-service:pom.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <parent>
 6         <artifactId>taotao-manager</artifactId>
 7         <groupId>com.taotao</groupId>
 8         <version>1.0-SNAPSHOT</version>
 9     </parent>
10     <modelVersion>4.0.0</modelVersion>
11 
12     <artifactId>taotao-manager-service</artifactId>
13 
14     <dependencies>
15         <!--依赖dao-->
16         <dependency>
17             <artifactId>taotao-manager-dao</artifactId>
18             <groupId>com.taotao</groupId>
19             <version>1.0-SNAPSHOT</version>
20         </dependency>
21 
22         <!--加载spring-->
23         <dependency>
24             <groupId>org.springframework</groupId>
25             <artifactId>spring-context</artifactId>
26         </dependency>
27         <dependency>
28             <groupId>org.springframework</groupId>
29             <artifactId>spring-beans</artifactId>
30         </dependency>
31         <dependency>
32             <groupId>org.springframework</groupId>
33             <artifactId>spring-webmvc</artifactId>
34         </dependency>
35         <dependency>
36             <groupId>org.springframework</groupId>
37             <artifactId>spring-jdbc</artifactId>
38         </dependency>
39         <dependency>
40             <groupId>org.springframework</groupId>
41             <artifactId>spring-aspects</artifactId>
42         </dependency>
43         <dependency>
44             <groupId>org.springframework</groupId>
45             <artifactId>spring-context-support</artifactId>
46         </dependency>
47     </dependencies>
48 </project>

3.2 添加模块taotao-manager-web表现层,打包方式为war,同样taotao-manager上右键New → Module → Next,如下图所示,
只不过这里选择webapp这项不同,点next下一步

pom.xml

 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/maven-v4_0_0.xsd">
 3     <parent>
 4         <artifactId>taotao-manager</artifactId>
 5         <groupId>com.taotao</groupId>
 6         <version>1.0-SNAPSHOT</version>
 7     </parent>
 8     <modelVersion>4.0.0</modelVersion>
 9     <artifactId>taotao-manager-web</artifactId>
10     <packaging>war</packaging>
11     <name>taotao-manager-web Maven Webapp</name>
12     <url>http://maven.apache.org</url>
13 
14     <!--添加依赖-->
15     <dependencies>
16         <dependency>
17             <groupId>com.taotao</groupId>
18             <artifactId>taotao-manager-service</artifactId>
19             <version>1.0-SNAPSHOT</version>
20         </dependency>
21 
22         <!-- JSP相关 -->
23         <dependency>
24             <groupId>jstl</groupId>
25             <artifactId>jstl</artifactId>
26         </dependency>
27         <dependency>
28             <groupId>javax.servlet</groupId>
29             <artifactId>servlet-api</artifactId>
30             <scope>provided</scope>
31         </dependency>
32         <dependency>
33             <groupId>javax.servlet</groupId>
34             <artifactId>jsp-api</artifactId>
35             <scope>provided</scope>
36         </dependency>
37         <!-- 文件上传组件 -->
38         <dependency>
39             <groupId>commons-fileupload</groupId>
40             <artifactId>commons-fileupload</artifactId>
41         </dependency>
42     </dependencies>
43     <build>
44         <finalName>taotao-manager-web</finalName>
45     </build>
46 </project>

4. 右上角Edit Configurations

需要把taotao-parent、taotao-common等需要安装的都安装到本地仓库,然后点击下图中的绿色小三角就OK了。

 

 

参考:https://www.jianshu.com/p/616d193ccfed

下篇:taotao-整合SSM框架

posted @ 2019-07-15 17:01  清晨的第一抹阳光  阅读(864)  评论(0编辑  收藏  举报