淘淘商城项目技术点-1.2:使用IntelliJ IDEA创建Maven项目

 

 

 

 

 

目标:

taotao-parent:父工程,打包方式pom,管理jar包的版本号。

       |           项目中所有工程都应该继承父工程。

  |--taotao-common:通用的工具类通用的pojo,util。打包方式jar

  |--taotao-manager:服务层工程。聚合工程。Pom工程

    |--taotao-manager-dao:打包方式jar

    |--taotao-manager-pojo:打包方式jar

    |--taotao-manager-interface:打包方式jar

    |--taotao-manager-service:打包方式:war  (为了发布服务的方便)

  |--taotao-manager-web:表现层工程。打包方式war

 

 第一步  创建一个空的项目,命名为taotao1,完成后会自动跳出Project Structure窗口,项目Modules下添加父工程。

 

第二步  按步骤添加其他子工程,聚合工程和打包方式为jar的工程不需要生成骨架,打包方式为war的可根据maven-archetype-webapp生成骨架(模板),自动生成web.xml。

按上面方法创建taotao1-manger-web工程,其打包方式为war。

 

第三步  配置聚合工程taotao1-parent,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     <modelVersion>4.0.0</modelVersion>
  6 
  7     <groupId>com.taotao</groupId>
  8     <artifactId>taotao-parent</artifactId>
  9     <version>1.0-SNAPSHOT</version>
 10     <packaging>pom</packaging>
 11 
 12     <!-- 集中定义依赖版本号 -->
 13     <properties>
 14         <junit.version>4.12</junit.version>
 15         <spring.version>4.2.4.RELEASE</spring.version>
 16         <mybatis.version>3.2.8</mybatis.version>
 17         <mybatis.spring.version>1.2.2</mybatis.spring.version>
 18         <mybatis.paginator.version>1.2.15</mybatis.paginator.version>
 19         <mysql.version>5.1.32</mysql.version>
 20         <slf4j.version>1.6.4</slf4j.version>
 21         <jackson.version>2.4.2</jackson.version>
 22         <druid.version>1.0.9</druid.version>
 23         <httpclient.version>4.3.5</httpclient.version>
 24         <jstl.version>1.2</jstl.version>
 25         <servlet-api.version>2.5</servlet-api.version>
 26         <jsp-api.version>2.0</jsp-api.version>
 27         <joda-time.version>2.5</joda-time.version>
 28         <commons-lang3.version>3.3.2</commons-lang3.version>
 29         <commons-io.version>1.3.2</commons-io.version>
 30         <commons-net.version>3.3</commons-net.version>
 31         <pagehelper.version>3.4.2-fix</pagehelper.version>
 32         <jsqlparser.version>0.9.1</jsqlparser.version>
 33         <commons-fileupload.version>1.3.1</commons-fileupload.version>
 34         <jedis.version>2.7.2</jedis.version>
 35         <solrj.version>4.10.3</solrj.version>
 36         <dubbo.version>2.5.3</dubbo.version>
 37         <zookeeper.version>3.4.7</zookeeper.version>
 38         <zkclient.version>0.1</zkclient.version>
 39         <activemq.version>5.13.0</activemq.version>
 40         <freemarker.version>2.3.23</freemarker.version>
 41         <quartz.version>2.2.2</quartz.version>
 42     </properties>
 43 
 44     <dependencyManagement>
 45         <dependencies>
 46             <!-- 时间操作组件 -->
 47             <dependency>
 48                 <groupId>joda-time</groupId>
 49                 <artifactId>joda-time</artifactId>
 50                 <version>${joda-time.version}</version>
 51             </dependency>
 52             <!-- Apache工具组件 -->
 53             <dependency>
 54                 <groupId>org.apache.commons</groupId>
 55                 <artifactId>commons-lang3</artifactId>
 56                 <version>${commons-lang3.version}</version>
 57             </dependency>
 58             <dependency>
 59                 <groupId>org.apache.commons</groupId>
 60                 <artifactId>commons-io</artifactId>
 61                 <version>${commons-io.version}</version>
 62             </dependency>
 63             <dependency>
 64                 <groupId>commons-net</groupId>
 65                 <artifactId>commons-net</artifactId>
 66                 <version>${commons-net.version}</version>
 67             </dependency>
 68             <!-- Jackson Json处理工具包 -->
 69             <dependency>
 70                 <groupId>com.fasterxml.jackson.core</groupId>
 71                 <artifactId>jackson-databind</artifactId>
 72                 <version>${jackson.version}</version>
 73             </dependency>
 74             <!-- httpclient -->
 75             <dependency>
 76                 <groupId>org.apache.httpcomponents</groupId>
 77                 <artifactId>httpclient</artifactId>
 78                 <version>${httpclient.version}</version>
 79             </dependency>
 80             <!-- quartz任务调度框架 -->
 81             <dependency>
 82                 <groupId>org.quartz-scheduler</groupId>
 83                 <artifactId>quartz</artifactId>
 84                 <version>${quartz.version}</version>
 85             </dependency>
 86             <!-- 单元测试 -->
 87             <dependency>
 88                 <groupId>junit</groupId>
 89                 <artifactId>junit</artifactId>
 90                 <version>${junit.version}</version>
 91                 <scope>test</scope>
 92             </dependency>
 93             <!-- 日志处理 -->
 94             <dependency>
 95                 <groupId>org.slf4j</groupId>
 96                 <artifactId>slf4j-log4j12</artifactId>
 97                 <version>${slf4j.version}</version>
 98             </dependency>
 99             <!-- Mybatis -->
100             <dependency>
101                 <groupId>org.mybatis</groupId>
102                 <artifactId>mybatis</artifactId>
103                 <version>${mybatis.version}</version>
104             </dependency>
105             <dependency>
106                 <groupId>org.mybatis</groupId>
107                 <artifactId>mybatis-spring</artifactId>
108                 <version>${mybatis.spring.version}</version>
109             </dependency>
110             <dependency>
111                 <groupId>com.github.miemiedev</groupId>
112                 <artifactId>mybatis-paginator</artifactId>
113                 <version>${mybatis.paginator.version}</version>
114             </dependency>
115             <dependency>
116                 <groupId>com.github.pagehelper</groupId>
117                 <artifactId>pagehelper</artifactId>
118                 <version>${pagehelper.version}</version>
119             </dependency>
120             <!-- MySql -->
121             <dependency>
122                 <groupId>mysql</groupId>
123                 <artifactId>mysql-connector-java</artifactId>
124                 <version>${mysql.version}</version>
125             </dependency>
126             <!-- 连接池 -->
127             <dependency>
128                 <groupId>com.alibaba</groupId>
129                 <artifactId>druid</artifactId>
130                 <version>${druid.version}</version>
131             </dependency>
132             <!-- Spring -->
133             <dependency>
134                 <groupId>org.springframework</groupId>
135                 <artifactId>spring-context</artifactId>
136                 <version>${spring.version}</version>
137             </dependency>
138             <dependency>
139                 <groupId>org.springframework</groupId>
140                 <artifactId>spring-beans</artifactId>
141                 <version>${spring.version}</version>
142             </dependency>
143             <dependency>
144                 <groupId>org.springframework</groupId>
145                 <artifactId>spring-webmvc</artifactId>
146                 <version>${spring.version}</version>
147             </dependency>
148             <dependency>
149                 <groupId>org.springframework</groupId>
150                 <artifactId>spring-jdbc</artifactId>
151                 <version>${spring.version}</version>
152             </dependency>
153             <dependency>
154                 <groupId>org.springframework</groupId>
155                 <artifactId>spring-aspects</artifactId>
156                 <version>${spring.version}</version>
157             </dependency>
158             <dependency>
159                 <groupId>org.springframework</groupId>
160                 <artifactId>spring-jms</artifactId>
161                 <version>${spring.version}</version>
162             </dependency>
163             <dependency>
164                 <groupId>org.springframework</groupId>
165                 <artifactId>spring-context-support</artifactId>
166                 <version>${spring.version}</version>
167             </dependency>
168             <!-- JSP相关 -->
169             <dependency>
170                 <groupId>jstl</groupId>
171                 <artifactId>jstl</artifactId>
172                 <version>${jstl.version}</version>
173             </dependency>
174             <dependency>
175                 <groupId>javax.servlet</groupId>
176                 <artifactId>servlet-api</artifactId>
177                 <version>${servlet-api.version}</version>
178                 <scope>provided</scope>
179             </dependency>
180             <dependency>
181                 <groupId>javax.servlet</groupId>
182                 <artifactId>jsp-api</artifactId>
183                 <version>${jsp-api.version}</version>
184                 <scope>provided</scope>
185             </dependency>
186             <!-- 文件上传组件 -->
187             <dependency>
188                 <groupId>commons-fileupload</groupId>
189                 <artifactId>commons-fileupload</artifactId>
190                 <version>${commons-fileupload.version}</version>
191             </dependency>
192             <!-- Redis客户端 -->
193             <dependency>
194                 <groupId>redis.clients</groupId>
195                 <artifactId>jedis</artifactId>
196                 <version>${jedis.version}</version>
197             </dependency>
198             <!-- solr客户端 -->
199             <dependency>
200                 <groupId>org.apache.solr</groupId>
201                 <artifactId>solr-solrj</artifactId>
202                 <version>${solrj.version}</version>
203             </dependency>
204             <!-- dubbo相关 -->
205             <dependency>
206                 <groupId>com.alibaba</groupId>
207                 <artifactId>dubbo</artifactId>
208                 <version>${dubbo.version}</version>
209             </dependency>
210             <dependency>
211                 <groupId>org.apache.zookeeper</groupId>
212                 <artifactId>zookeeper</artifactId>
213                 <version>${zookeeper.version}</version>
214             </dependency>
215             <dependency>
216                 <groupId>com.github.sgroschupf</groupId>
217                 <artifactId>zkclient</artifactId>
218                 <version>${zkclient.version}</version>
219             </dependency>
220             <dependency>
221                 <groupId>org.apache.activemq</groupId>
222                 <artifactId>activemq-all</artifactId>
223                 <version>${activemq.version}</version>
224             </dependency>
225             <dependency>
226                 <groupId>org.freemarker</groupId>
227                 <artifactId>freemarker</artifactId>
228                 <version>${freemarker.version}</version>
229             </dependency>
230 
231         </dependencies>
232     </dependencyManagement>
233 
234     <build>
235         <finalName>${project.artifactId}</finalName>
236         <plugins>
237             <!-- 资源文件拷贝插件 -->
238             <plugin>
239                 <groupId>org.apache.maven.plugins</groupId>
240                 <artifactId>maven-resources-plugin</artifactId>
241                 <version>2.7</version>
242                 <configuration>
243                     <encoding>UTF-8</encoding>
244                 </configuration>
245             </plugin>
246             <!-- java编译插件 -->
247             <plugin>
248                 <groupId>org.apache.maven.plugins</groupId>
249                 <artifactId>maven-compiler-plugin</artifactId>
250                 <version>3.2</version>
251                 <configuration>
252                     <source>1.7</source>
253                     <target>1.7</target>
254                     <encoding>UTF-8</encoding>
255                 </configuration>
256             </plugin>
257         </plugins>
258         <pluginManagement>
259             <plugins>
260                 <!-- 配置Tomcat插件 -->
261                 <plugin>
262                     <groupId>org.apache.tomcat.maven</groupId>
263                     <artifactId>tomcat7-maven-plugin</artifactId>
264                     <version>2.2</version>
265                 </plugin>
266 
267                 <!-- 配置打包时跳过测试 ,首次配置使用的时候会自动联网进行下载 -->
268                 <plugin>
269                     <groupId>org.apache.maven.plugins</groupId>
270                     <artifactId>maven-surefire-plugin</artifactId>
271                     <version>2.12.4</version>
272                 </plugin>
273             </plugins>
274         </pluginManagement>
275     </build>
276 </project>
View Code

第四步  根据需要的jar依赖配置其他工程的pom.xml

  • taotao1-manager-dao需要的依赖有mybatis、mysql、连接池,以及taotao1-manager-pojo。
  • taotao1-manager-pojo暂不需要依赖。
  • taotao1-manager-interface需要taotao1-manager-pojo依赖。
  • taotao1-manager-service需要pojo、dao、interface、spring依赖,tomcat插件(此项互联网搜索配置)等。
  • taotao1-manager-web需要spring、pojo、interface、文件上传、JSP等。

第五步  当所有pom.xml配置完毕后,运行工程前,需要根据依赖关系或顺序install各个工程,打包成相应方式,放入到repository才可正常运行项目。

 

posted on 2019-03-09 11:00  yadDRL  阅读(741)  评论(0编辑  收藏  举报

导航