基于 Maven 的多模块 Java ( Spring ) 项目构建
2018-06-18 00:45:36来源:未知 阅读 ()
索引:
开源Spring解决方案--lm.solution
参看代码 GitHub:
solution/pom.xml
pojo/pom.xml
mapper/pom.xml
common/pom.xml
service/pom.xml
console/pom.xml
web/pom.xml
webapi/pom.xml
webservice/pom.xml
一、Intelij IDEA 中构建 maven 项目及模块
1.新建 maven 项目,在IDE中的菜单位置
2.项目中新建模块在IDE中的菜单位置
3.整个项目的结构
二、Maven 模块及模块关系要点讲解
1.solution/pom.xml
<groupId>lm.solution</groupId>
<artifactId>solution</artifactId>
<version>1.0-SNAPSHOT</version>
讲解:
groupId :模块项目归属组织名称
artifactId:项目内模块名称
version:模块的版本号
这三个属性唯一的标识了一个模块,也被称为 maven 坐标。
<modules>
<module>webapi</module>
... ...
</modules>
讲解:
因为 solution 这个模块是做为项目父模块存在的,在 modules 标签内就指明了该模块都包含哪些子模块:
webapi、web、common、service、mapper、pojo、console、webservice。
<packaging>pom</packaging>
讲解:
因为 solution 模块将包含多个子模块,所以这里的打包方式选择 pom 值。
<properties>
<spring.version>4.3.13.RELEASE</spring.version>
... ...
</properties>
讲解:
在父模块中定义的 properties maven 属性变量,除了在本模块中可直接引用外,在所有的子模块中也可以直接被引用,
也就是说在子模块中就可以不必在重新定义 maven的属性变量了,如 spring.version 这个属性变量,在所有模块及子模块中
可以被直接使用 ${spring.version} 。
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
... ...
</dependency>
... ...
</dependencies>
讲解:
在父模块中定义的类库依赖,除了在父模块中会做引用以外,在所有子模块中也都会做自动的引用,
所以在子模块中就不必添加 dependencies 中的依赖了,如 junit 这个第三方类库,在子模块中 maven
会自动继承父模块的 junit 依赖,子模块中就不必再添加 junit 的类库依赖了。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
... ...
</dependencies>
</dependencyManagement>
讲解:
有的类库依赖,在部分子模块中需要,在部分子模块中不需要,此时,就可将依赖关系放到此节点中,
例如:mybatis 这个第三方 orm 库,在 pojo(仅是映射关系的实体层) 子模块中没有依赖,而在 mapper(orm 存储仓层) 这个
子模块中就是关键依赖。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
... ...
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat8-maven-plugin</artifactId>
... ...
</plugin>
</plugins>
</pluginManagement>
</build>
讲解:
这里 plugins 与 pluginManagement 可参看上面讲解到的 dependencies 与 dependencyManagement 的作用,他们作用
类似,因为每个模块都需要 maven-compiler-plugin 编译插件,所以直接将其放到父模块的 plugins 标签内,而 tomcat8-maven-plugin
插件只有 web 子模块需要,所以将其放到 pluginManagement 标签中。
solution/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/xsd/maven-4.0.0.xsd"> 3 <modelVersion>4.0.0</modelVersion> 4 5 <groupId>lm.solution</groupId> 6 <artifactId>solution</artifactId> 7 <version>1.0-SNAPSHOT</version> 8 <modules> 9 <module>webapi</module> 10 <module>web</module> 11 <module>common</module> 12 <module>service</module> 13 <module>mapper</module> 14 <module>pojo</module> 15 <module>console</module> 16 <module>webservice</module> 17 </modules> 18 <packaging>pom</packaging> 19 20 <name>solution</name> 21 <url>http://maven.apache.org</url> 22 23 <properties> 24 <!--编译字符集--> 25 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 26 <!-- spring --> 27 <spring.version>4.3.13.RELEASE</spring.version> 28 <!-- log4j --> 29 <slf4j.version>1.7.7</slf4j.version> 30 <log4j.version>1.2.17</log4j.version> 31 <!-- jackson --> 32 <jackson.version>2.9.4</jackson.version> 33 <!-- junit --> 34 <junit.version>4.12</junit.version> 35 <!-- aspectj --> 36 <aspectj.version>1.8.13</aspectj.version> 37 <!-- cglib --> 38 <cglib.version>3.1</cglib.version> 39 <!-- mybatis --> 40 <mybatis.version>3.4.5</mybatis.version> 41 <!-- mybatis-spring --> 42 <mybatisSpring.version>1.3.1</mybatisSpring.version> 43 <!--mysql-connector--> 44 <mysql.version>5.1.34</mysql.version> 45 <!--druid--> 46 <druid.version>1.0.5</druid.version> 47 <!--javax.servlet--> 48 <javaxServlet.version>3.0.1</javaxServlet.version> 49 <!--jsp-api--> 50 <jspApi.version>2.2</jspApi.version> 51 <!--jstl--> 52 <jstl.version>1.2</jstl.version> 53 <!--json-lib--> 54 <jsonLib.version>2.1</jsonLib.version> 55 <!--jackson old--> 56 <jacksonOld.version>1.9.13</jacksonOld.version> 57 <!--dom4j--> 58 <dom4j.version>1.6.1</dom4j.version> 59 <!--ehcache core--> 60 <ehcacheCore.version>2.6.9</ehcacheCore.version> 61 <!--ehcache web--> 62 <ehcacheWeb.version>2.0.4</ehcacheWeb.version> 63 <!--commons-fileupload--> 64 <commonsFileupload.version>1.3.1</commonsFileupload.version> 65 <!--commons-io--> 66 <commonsIo.version>2.4</commonsIo.version> 67 <!--commons-codec--> 68 <commonsCodec.version>1.9</commonsCodec.version> 69 <!--commons-collections4--> 70 <commonsCollections4.version>4.0</commonsCollections4.version> 71 <!--commons-beanutils--> 72 <commonsBeanutils.version>1.7.0</commonsBeanutils.version> 73 <!--freemarker--> 74 <freemarker.version>2.3.19</freemarker.version> 75 <!-- poi poi-ooxml --> 76 <poi.version>3.9</poi.version> 77 <!--org.apache.httpcomponents--> 78 <httpcore.version>4.4.8</httpcore.version> 79 <httpclient.version>4.5.4</httpclient.version> 80 <!-- jaxws-rt --> 81 <jaxwsRt.version>2.3.0</jaxwsRt.version> 82 <!-- jedis --> 83 <jedis.version>2.9.0</jedis.version> 84 <!-- rabbitmq --> 85 <amqpClient.version>5.1.2</amqpClient.version> 86 <!--fastjson--> 87 <fastjson.version>1.2.46</fastjson.version> 88 <!-- jsr250 --> 89 <jsr250.version>1.0</jsr250.version> 90 </properties> 91 92 <dependencies> 93 <!--单元测试依赖 --> 94 <dependency> 95 <groupId>junit</groupId> 96 <artifactId>junit</artifactId> 97 <version>RELEASE</version> 98 <!--test 说明这个包的存活是在test周期,也就是发布时将不包含这个jar包--> 99 <scope>test</scope> 100 </dependency> 101 <!--spring单元测试依赖 --> 102 <dependency> 103 <groupId>org.springframework</groupId> 104 <artifactId>spring-test</artifactId> 105 <version>${spring.version}</version> 106 <scope>test</scope> 107 </dependency> 108 <!-- spring --> 109 <dependency> 110 <groupId>org.springframework</groupId> 111 <!-- 因依赖 会自动引入 spring-aop spring-beans spring-core spring-expression 四个包 --> 112 <artifactId>spring-context</artifactId> 113 <version>${spring.version}</version> 114 </dependency> 115 <dependency> 116 <groupId>org.springframework</groupId> 117 <artifactId>spring-context-support</artifactId> 118 <version>${spring.version}</version> 119 </dependency> 120 <dependency> 121 <groupId>org.springframework</groupId> 122 <artifactId>spring-aspects</artifactId> 123 <version>${spring.version}</version> 124 </dependency> 125 <dependency> 126 <groupId>org.springframework</groupId> 127 <artifactId>spring-tx</artifactId> 128 <version>${spring.version}</version> 129 </dependency> 130 <dependency> 131 <groupId>org.springframework</groupId> 132 <artifactId>spring-jdbc</artifactId> 133 <version>${spring.version}</version> 134 </dependency> 135 <!-- aspectj AOP --> 136 <dependency> 137 <groupId>org.aspectj</groupId> 138 <artifactId>aspectjrt</artifactId> 139 <version>${aspectj.version}</version> 140 </dependency> 141 <dependency> 142 <groupId>org.aspectj</groupId> 143 <artifactId>aspectjweaver</artifactId> 144 <version>${aspectj.version}</version> 145 </dependency> 146 <!-- 映入JSON jackson --> 147 <dependency> 148 <groupId>com.fasterxml.jackson.core</groupId> 149 <artifactId>jackson-annotations</artifactId> 150 <version>${jackson.version}</version> 151 </dependency> 152 <dependency> 153 <groupId>com.fasterxml.jackson.core</groupId> 154 <artifactId>jackson-databind</artifactId> 155 <version>${jackson.version}</version> 156 </dependency> 157 <dependency> 158 <groupId>com.fasterxml.jackson.core</groupId> 159 <artifactId>jackson-core</artifactId> 160 <version>${jackson.version}</version> 161 </dependency> 162 <dependency> 163 <groupId>com.fasterxml.jackson.dataformat</groupId> 164 <artifactId>jackson-dataformat-xml</artifactId> 165 <version>${jackson.version}</version> 166 </dependency> 167 <!-- 日志文件管理包 --> 168 <dependency> 169 <groupId>log4j</groupId> 170 <artifactId>log4j</artifactId> 171 <version>${log4j.version}</version> 172 </dependency> 173 <dependency> 174 <groupId>org.slf4j</groupId> 175 <artifactId>slf4j-api</artifactId> 176 <version>${slf4j.version}</version> 177 </dependency> 178 <dependency> 179 <groupId>org.slf4j</groupId> 180 <artifactId>slf4j-log4j12</artifactId> 181 <version>${slf4j.version}</version> 182 </dependency> 183 </dependencies> 184 185 <dependencyManagement> 186 <dependencies> 187 <!--spring web--> 188 <dependency> 189 <groupId>org.springframework</groupId> 190 <artifactId>spring-web</artifactId> 191 <version>${spring.version}</version> 192 </dependency> 193 <dependency> 194 <groupId>org.springframework</groupId> 195 <artifactId>spring-webmvc</artifactId> 196 <version>${spring.version}</version> 197 </dependency> 198 <!--cglib--> 199 <dependency> 200 <groupId>cglib</groupId> 201 <artifactId>cglib</artifactId> 202 <version>${cglib.version}</version> 203 </dependency> 204 <!-- mybatis --> 205 <dependency> 206 <groupId>org.mybatis</groupId> 207 <artifactId>mybatis</artifactId> 208 <version>${mybatis.version}</version> 209 </dependency> 210 <dependency> 211 <groupId>org.mybatis</groupId> 212 <artifactId>mybatis-spring</artifactId> 213 <version>${mybatisSpring.version}</version> 214 </dependency> 215 <!-- Mysql数据库驱动包 --> 216 <dependency> 217 <groupId>mysql</groupId> 218 <artifactId>mysql-connector-java</artifactId> 219 <version>${mysql.version}</version> 220 </dependency> 221 <!-- connection pool --> 222 <dependency> 223 <groupId>com.alibaba</groupId> 224 <artifactId>druid</artifactId> 225 <version>${druid.version}</version> 226 <!--<scope>runtime</scope>--> 227 </dependency> 228 <!--servlet--> 229 <dependency> 230 <groupId>javax.servlet</groupId> 231 <artifactId>javax.servlet-api</artifactId> 232 <version>${javaxServlet.version}</version> 233 <scope>provided</scope> 234 </dependency> 235 <dependency> 236 <groupId>javax.servlet.jsp</groupId> 237 <artifactId>jsp-api</artifactId> 238 <version>${jspApi.version}</version> 239 <scope>provided</scope> 240 </dependency> 241 <dependency> 242 <groupId>javax.servlet</groupId> 243 <artifactId>jstl</artifactId> 244 <version>${jstl.version}</version> 245 </dependency> 246 <!-- 映入JSON lib --> 247 <dependency> 248 <groupId>net.sf.json-lib</groupId> 249 <artifactId>json-lib</artifactId> 250 <version>${jsonLib.version}</version> 251 <classifier>jdk15</classifier> 252 </dependency> 253 <!-- jackson old --> 254 <dependency> 255 <groupId>org.codehaus.jackson</groupId> 256 <artifactId>jackson-core-asl</artifactId> 257 <version>${jacksonOld.version}</version> 258 </dependency> 259 <dependency> 260 <groupId>org.codehaus.jackson</groupId> 261 <artifactId>jackson-mapper-asl</artifactId> 262 <version>${jacksonOld.version}</version> 263 </dependency> 264 <!-- 用dom4j解析xml文件 --> 265 <dependency> 266 <groupId>dom4j</groupId> 267 <artifactId>dom4j</artifactId> 268 <version>${dom4j.version}</version> 269 </dependency> 270 <!-- ehcache --> 271 <dependency> 272 <groupId>net.sf.ehcache</groupId> 273 <artifactId>ehcache-core</artifactId> 274 <version>${ehcacheCore.version}</version> 275 </dependency> 276 <dependency> 277 <groupId>net.sf.ehcache</groupId> 278 <artifactId>ehcache-web</artifactId> 279 <version>${ehcacheWeb.version}</version> 280 </dependency> 281 <!-- 上传组件包 --> 282 <dependency> 283 <groupId>commons-fileupload</groupId> 284 <artifactId>commons-fileupload</artifactId> 285 <version>${commonsFileupload.version}</version> 286 </dependency> 287 <dependency> 288 <groupId>commons-io</groupId> 289 <artifactId>commons-io</artifactId> 290 <version>${commonsIo.version}</version> 291 </dependency> 292 <dependency> 293 <groupId>commons-codec</groupId> 294 <artifactId>commons-codec</artifactId> 295 <version>${commonsCodec.version}</version> 296 </dependency> 297 <dependency> 298 <groupId>org.apache.commons</groupId> 299 <artifactId>commons-collections4</artifactId> 300 <version>${commonsCollections4.version}</version> 301 </dependency> 302 <dependency> 303 <groupId>org.apache.commons</groupId> 304 <artifactId>commons-lang3</artifactId> 305 <version>3.3.2</version> 306 </dependency> 307 <!-- commons-beanutils --> 308 <dependency> 309 <groupId>commons-beanutils</groupId> 310 <artifactId>commons-beanutils</artifactId> 311 <version>${commonsBeanutils.version}</version> 312 <exclusions> 313 <exclusion> 314 <groupId>commons-logging</groupId> 315 <artifactId>commons-logging</artifactId> 316 </exclusion> 317 </exclusions> 318 </dependency> 319 <!-- freemarker --> 320 <dependency> 321 <groupId>org.freemarker</groupId> 322 <artifactId>freemarker</artifactId> 323 <version>${freemarker.version}</version> 324 </dependency> 325 <!-- poi --> 326 <dependency> 327 <groupId>org.apache.poi</groupId> 328 <artifactId>poi</artifactId> 329 <version>${poi.version}</version> 330 </dependency> 331 <dependency> 332 <groupId>org.apache.poi</groupId> 333 <artifactId>poi-ooxml</artifactId> 334 <version>${poi.version}</version> 335 </dependency> 336 <!-- org.apache.httpcomponents --> 337 <dependency> 338 <groupId>org.apache.httpcomponents</groupId> 339 <artifactId>httpcore</artifactId> 340 <version>${httpcore.version}</version> 341 </dependency> 342 <dependency> 343 <groupId>org.apache.httpcomponents</groupId> 344 <artifactId>httpclient</artifactId> 345 <version>${httpclient.version}</version> 346 </dependency> 347 <!-- com.sun.xml.ws/jaxws-rt --> 348 <dependency> 349 <groupId>com.sun.xml.ws</groupId> 350 <artifactId>jaxws-rt</artifactId> 351 <version>${jaxwsRt.version}</version> 352 </dependency> 353 <!-- redis.clients/jedis --> 354 <dependency> 355 <groupId>redis.clients</groupId> 356 <artifactId>jedis</artifactId> 357 <version>${jedis.version}</version> 358 </dependency> 359 <!-- com.rabbitmq/amqp-client --> 360 <dependency> 361 <groupId>com.rabbitmq</groupId> 362 <artifactId>amqp-client</artifactId> 363 <version>${amqpClient.version}</version> 364 </dependency> 365 <!-- com.alibaba/fastjson --> 366 <dependency> 367 <groupId>com.alibaba</groupId> 368 <artifactId>fastjson</artifactId> 369 <version>${fastjson.version}</version> 370 </dependency> 371 <!-- javax.annotation/jsr250-api --> 372 <dependency> 373 <groupId>javax.annotation</groupId> 374 <artifactId>jsr250-api</artifactId> 375 <version>${jsr250.version}</version> 376 </dependency> 377 </dependencies> 378 </dependencyManagement> 379 380 <build> 381 <plugins> 382 <!-- java编译插件 --> 383 <plugin> 384 <groupId>org.apache.maven.plugins</groupId> 385 <artifactId>maven-compiler-plugin</artifactId> 386 <version>3.2</version> 387 <configuration> 388 <source>1.8</source> 389 <target>1.8</target> 390 <encoding>UTF-8</encoding> 391 </configuration> 392 </plugin> 393 </plugins> 394 395 <pluginManagement> 396 <plugins> 397 <!-- 配置Tomcat插件 --> 398 <plugin> 399 <groupId>org.apache.tomcat.maven</groupId> 400 <artifactId>tomcat8-maven-plugin</artifactId> 401 <version>3.0-r1756463</version> 402 </plugin> 403 </plugins> 404 </pluginManagement> 405 </build> 406 407 </project>
2.pojo/pom.xml
这个模块是做为实体层的。
重复内容不在讲解,参考上文的说明。
<parent>
<artifactId>solution</artifactId>
<groupId>lm.solution</groupId>
... ...
</parent>
讲解:
因为 pojo 模块是 solution 模块的子模块,所以要在 parent 标签内指明父模块是 solution 模块的坐标。
<packaging>jar</packaging>
讲解:
因为这里 pojo 模块是做为其它模块依赖的类库使用的,所以打包方式为 jar 值。
pojo/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/xsd/maven-4.0.0.xsd"> 3 <parent> 4 <artifactId>solution</artifactId> 5 <groupId>lm.solution</groupId> 6 <version>1.0-SNAPSHOT</version> 7 </parent> 8 <modelVersion>4.0.0</modelVersion> 9 10 <groupId>lm.solution</groupId> 11 <artifactId>pojo</artifactId> 12 <version>1.0-SNAPSHOT</version> 13 <packaging>jar</packaging> 14 15 <name>pojo</name> 16 <url>http://maven.apache.org</url> 17 18 <properties> 19 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 20 </properties> 21 22 <dependencies> 23 <!-- Module --> 24 25 <!-- Libary --> 26 27 </dependencies> 28 </project>
3.mapper/pom.xml
这个模块是做为存储仓层的。
重复内容不在讲解,参考上文的说明。
<dependencies>
<dependency>
<groupId>lm.solution</groupId>
<artifactId>pojo</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
... ...
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
... ...
</dependencies>
讲解:
因为 mapper 模块依赖 pojo 模块,所以这里引入 pojo 的依赖坐标,
又由于该模块需要第三方mybatis类库,所以 这里引入mybatis 的 maven 坐标,
上文中 solution 父模块 已经在 dependencyManagement 指明了,所以这里就不用再指明 version 了。
mapper/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/xsd/maven-4.0.0.xsd"> 3 <parent> 4 <artifactId>solution</artifactId> 5 <groupId>lm.solution</groupId> 6 <version>1.0-SNAPSHOT</version> 7 </parent> 8 <modelVersion>4.0.0</modelVersion> 9 10 <groupId>lm.solution</groupId> 11 <artifactId>mapper</artifactId> 12 <version>1.0-SNAPSHOT</version> 13 <packaging>jar</packaging> 14 15 <name>mapper</name> 16 <url>http://maven.apache.org</url> 17 18 <properties> 19 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 20 </properties> 21 22 <dependencies> 23 <!--Module--> 24 <dependency> 25 <groupId>lm.solution</groupId> 26 <artifactId>pojo</artifactId> 27 <version>1.0-SNAPSHOT</version> 28 </dependency> 29 30 <!--Libary--> 31 <dependency><!-- mybatis核心包 --> 32 <groupId>org.mybatis</groupId> 33 <artifactId>mybatis</artifactId> 34 </dependency> 35 <dependency><!-- Mysql数据库驱动包 --> 36 <groupId>mysql</groupId> 37 <artifactId>mysql-connector-java</artifactId> 38 </dependency> 39 <dependency><!-- connection pool --> 40 <groupId>com.alibaba</groupId> 41 <artifactId>druid</artifactId> 42 <scope>runtime</scope> 43 </dependency> 44 </dependencies> 45 </project>
4.common/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/xsd/maven-4.0.0.xsd"> 3 <parent> 4 <artifactId>solution</artifactId> 5 <groupId>lm.solution</groupId> 6 <version>1.0-SNAPSHOT</version> 7 </parent> 8 <modelVersion>4.0.0</modelVersion> 9 10 <groupId>lm.solution</groupId> 11 <artifactId>common</artifactId> 12 <version>1.0-SNAPSHOT</version> 13 <packaging>jar</packaging> 14 15 <name>common</name> 16 <url>http://maven.apache.org</url> 17 18 <dependencies> 19 <!--Module--> 20 <dependency> 21 <groupId>lm.solution</groupId> 22 <artifactId>pojo</artifactId> 23 <version>1.0-SNAPSHOT</version> 24 </dependency> 25 26 <!--Libary--> 27 <!--spring web--> 28 <dependency> 29 <groupId>org.springframework</groupId> 30 <artifactId>spring-webmvc</artifactId> 31 </dependency> 32 <!-- poi --> 33 <dependency> 34 <groupId>org.apache.poi</groupId> 35 <artifactId>poi</artifactId> 36 </dependency> 37 <!-- poi-ooxml --> 38 <dependency> 39 <groupId>org.apache.poi</groupId> 40 <artifactId>poi-ooxml</artifactId> 41 </dependency> 42 <!--servlet--> 43 <dependency> 44 <groupId>javax.servlet</groupId> 45 <artifactId>javax.servlet-api</artifactId> 46 <scope>provided</scope> 47 </dependency> 48 <!-- org.apache.httpcomponents --> 49 <dependency> 50 <groupId>org.apache.httpcomponents</groupId> 51 <artifactId>httpcore</artifactId> 52 </dependency> 53 <dependency> 54 <groupId>org.apache.httpcomponents</groupId> 55 <artifactId>httpclient</artifactId> 56 </dependency> 57 <!--Commons--> 58 <dependency> 59 <groupId>org.apache.commons</groupId> 60 <artifactId>commons-collections4</artifactId> 61 </dependency> 62 <!-- redis.clients/jedis --> 63 <dependency> 64 <groupId>redis.clients</groupId> 65 <artifactId>jedis</artifactId> 66 </dependency> 67 <!-- com.rabbitmq/amqp-client --> 68 <dependency> 69 <groupId>com.rabbitmq</groupId> 70 <artifactId>amqp-client</artifactId> 71 </dependency> 72 </dependencies> 73 </project>
5.service/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/xsd/maven-4.0.0.xsd"> 3 <parent> 4 <artifactId>solution</artifactId> 5 <groupId>lm.solution</groupId> 6 <version>1.0-SNAPSHOT</version> 7 </parent> 8 <modelVersion>4.0.0</modelVersion> 9 10 <groupId>lm.solution</groupId> 11 <artifactId>service</artifactId> 12 <version>1.0-SNAPSHOT</version> 13 <packaging>jar</packaging> 14 15 <name>service</name> 16 <url>http://maven.apache.org</url> 17 18 <properties> 19 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 20 </properties> 21 22 <dependencies> 23 <!--Module--> 24 <dependency> 25 <groupId>lm.solution</groupId> 26 <artifactId>mapper</artifactId> 27 <version>1.0-SNAPSHOT</version> 28 </dependency> 29 30 <!--Libary--> 31 32 </dependencies> 33 </project>
6.console/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/xsd/maven-4.0.0.xsd"> 3 <parent> 4 <artifactId>solution</artifactId> 5 <groupId>lm.solution</groupId> 6 <version>1.0-SNAPSHOT</version> 7 </parent> 8 <modelVersion>4.0.0</modelVersion> 9 10 <groupId>lm.solution</groupId> 11 <artifactId>console</artifactId> 12 <version>1.0-SNAPSHOT</version> 13 <packaging>jar</packaging> 14 15 <name>console</name> 16 <url>http://maven.apache.org</url> 17 18 <properties> 19 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 20 </properties> 21 22 <dependencies> 23 <!-- Module --> 24 <dependency> 25 <groupId>lm.solution</groupId> 26 <artifactId>pojo</artifactId> 27 <version>1.0-SNAPSHOT</version> 28 </dependency> 29 <dependency> 30 <groupId>lm.solution</groupId> 31 <artifactId>common</artifactId> 32 <version>1.0-SNAPSHOT</version> 33 </dependency> 34 <dependency> 35 <groupId>lm.solution</groupId> 36 <artifactId>service</artifactId> 37 <version>1.0-SNAPSHOT</version> 38 </dependency> 39 40 <!-- Libary --> 41 <!-- jackson old --> 42 <dependency> 43 <groupId>org.codehaus.jackson</groupId> 44 <artifactId>jackson-core-asl</artifactId> 45 </dependency> 46 <dependency> 47 <groupId>org.codehaus.jackson</groupId> 48 <artifactId>jackson-mapper-asl</artifactId> 49 </dependency> 50 <dependency> 51 <groupId>com.rabbitmq</groupId> 52 <artifactId>amqp-client</artifactId> 53 </dependency> 54 <!-- com.alibaba/fastjson --> 55 <dependency> 56 <groupId>com.alibaba</groupId> 57 <artifactId>fastjson</artifactId> 58 </dependency> 59 <!-- commons-io --> 60 <dependency> 61 <groupId>commons-io</groupId> 62 <artifactId>commons-io</artifactId> 63 </dependency> 64 <!-- javax.annotation/jsr250-api --> 65 <dependency> 66 <groupId>javax.annotation</groupId> 67 <artifactId>jsr250-api</artifactId> 68 </dependency> 69 <!-- javax.servlet-api --> 70 <dependency> 71 <groupId>javax.servlet</groupId> 72 <artifactId>javax.servlet-api</artifactId> 73 </dependency> 74 75 <!-- other --> 76 <dependency> 77 <groupId>junit</groupId> 78 <artifactId>junit</artifactId> 79 <version>RELEASE</version> 80 </dependency> 81 <dependency> 82 <groupId>org.springframework</groupId> 83 <artifactId>spring-test</artifactId> 84 <version>4.3.13.RELEASE</version> 85 </dependency> 86 </dependencies> 87 88 89 </project>
7.web/pom.xml
这个模块是做为 web 站点的。
重复内容不在讲解,参考上文的说明。
<packaging>war</packaging>
讲解:
因为这模块在编译后是部署到 tomcat 容器的,所以这里采用的打包方式是 war 值。
web/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>solution</artifactId> 5 <groupId>lm.solution</groupId> 6 <version>1.0-SNAPSHOT</version> 7 </parent> 8 <modelVersion>4.0.0</modelVersion> 9 <groupId>lm.solution</groupId> 10 <artifactId>web</artifactId> 11 <packaging>war</packaging> 12 <version>1.0-SNAPSHOT</version> 13 <name>web Maven Webapp</name> 14 <url>http://maven.apache.org</url> 15 <dependencies> 16 <!--Module--> 17 <dependency> 18 <groupId>lm.solution</groupId> 19 <artifactId>service</artifactId> 20 <version>1.0-SNAPSHOT</version> 21 </dependency> 22 <dependency> 23 <groupId>lm.solution</groupId> 24 <artifactId>common</artifactId> 25 <version>1.0-SNAPSHOT</version> 26 </dependency> 27 28 <!--Libary--> 29 <!--spring mvc--> 30 <dependency> 31 <groupId>org.springframework</groupId> 32 <!--引入该包后,maven 会自动解析依赖,引入 spring-web 等包。--> 33 <artifactId>spring-webmvc</artifactId> 34 </dependency> 35 <!--cglib--> 36 <dependency> 37 <groupId>cglib</groupId> 38 <artifactId>cglib</artifactId> 39 </dependency> 40 <!-- mybatis核心包 --> 41 <dependency> 42 <groupId>org.mybatis</groupId> 43 <artifactId>mybatis</artifactId> 44 </dependency> 45 <!--mybatis spring 插件 --> 46 <dependency> 47 <groupId>org.mybatis</groupId> 48 <artifactId>mybatis-spring</artifactId> 49 </dependency> 50 <!-- Mysql数据库驱动包 --> 51 <dependency> 52 <groupId>mysql</groupId> 53 <artifactId>mysql-connector-java</artifactId> 54 </dependency> 55 <!-- connection pool --> 56 <dependency> 57 <groupId>com.alibaba</groupId> 58 <artifactId>druid</artifactId> 59 <!--<scope>runtime</scope>--> 60 </dependency> 61 <!--servlet--> 62 <dependency> 63 <groupId>javax.servlet</groupId> 64 <artifactId>javax.servlet-api</artifactId> 65 <scope>provided</scope> 66 </dependency> 67 <dependency> 68 <groupId>javax.servlet.jsp</groupId> 69 <artifactId>jsp-api</artifactId> 70 <scope>provided</scope> 71 </dependency> 72 <dependency> 73 <groupId>javax.servlet</groupId> 74 <artifactId>jstl</artifactId> 75 </dependency> 76 <!-- 映入JSON lib --> 77 <dependency> 78 <groupId>net.sf.json-lib</groupId> 79 <artifactId>json-lib</artifactId> 80 <classifier>jdk15</classifier> 81 </dependency> 82 <!-- 用dom4j解析xml文件 --> 83 <dependency> 84 <groupId>dom4j</groupId> 85 <artifactId>dom4j</artifactId> 86 </dependency> 87 <!-- ehcache --> 88 <dependency> 89 <groupId>net.sf.ehcache</groupId> 90 <artifactId>ehcache-core</artifactId> 91 </dependency> 92 <dependency> 93 <groupId>net.sf.ehcache</groupId> 94 <artifactId>ehcache-web</artifactId> 95 </dependency> 96 <!-- 上传组件包 --> 97 <dependency> 98 <groupId>commons-fileupload</groupId> 99 <artifactId>commons-fileupload</artifactId> 100 </dependency> 101 <dependency> 102 <groupId>commons-io</groupId> 103 <artifactId>commons-io</artifactId> 104 </dependency> 105 <!-- common others --> 106 <dependency> 107 <groupId>commons-codec</groupId> 108 <artifactId>commons-codec</artifactId> 109 </dependency> 110 <dependency> 111 <groupId>org.apache.commons</groupId> 112 <artifactId>commons-collections4</artifactId> 113 </dependency> 114 <dependency> 115 <groupId>org.apache.commons</groupId> 116 <artifactId>commons-lang3</artifactId> 117 </dependency> 118 <!-- commons-beanutils --> 119 <dependency> 120 <groupId>commons-beanutils</groupId> 121 <artifactId>commons-beanutils</artifactId> 122 <exclusions> 123 <exclusion> 124 <groupId>commons-logging</groupId> 125 <artifactId>commons-logging</artifactId> 126 </exclusion> 127 </exclusions> 128 </dependency> 129 <!-- freemarker --> 130 <dependency> 131 <groupId>org.freemarker</groupId> 132 <artifactId>freemarker</artifactId> 133 </dependency> 134 <!-- org.apache.httpcomponents --> 135 <dependency> 136 <groupId>org.apache.httpcomponents</groupId> 137 <artifactId>httpcore</artifactId> 138 </dependency> 139 <dependency> 140 <groupId>org.apache.httpcomponents</groupId> 141 <artifactId>httpclient</artifactId> 142 </dependency> 143 <!-- redis.clients/jedis --> 144 <dependency> 145 <groupId>redis.clients</groupId> 146 <artifactId>jedis</artifactId> 147 </dependency> 148 <!-- com.rabbitmq/amqp-client --> 149 <dependency> 150 <groupId>com.rabbitmq</groupId> 151 <artifactId>amqp-client</artifactId> 152 </dependency> 153 <!-- com.alibaba/fastjson --> 154 <dependency> 155 <groupId>com.alibaba</groupId> 156 <artifactId>fastjson</artifactId> 157 </dependency> 158 </dependencies> 159 <build> 160 <finalName>web</finalName> 161 162 <plugins> 163 <plugin> 164 <groupId>org.apache.tomcat.maven</groupId> 165 <artifactId>tomcat8-maven-plugin</artifactId> 166 </plugin> 167 </plugins> 168 </build> 169 </project>
8.webapi/pom.xml
这个模块是做为 Restful API 站点的。
重复内容不在讲解,参考上文的说明。
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 4 <parent> 5 <artifactId>solution</artifactId> 6 <groupId>lm.solution</groupId> 7 <version>1.0-SNAPSHOT</version> 8 </parent> 9 10 <modelVersion>4.0.0</modelVersion> 11 <groupId>lm.solution</groupId> 12 <artifactId>webapi</artifactId> 13 <packaging>war</packaging> 14 <version>1.0-SNAPSHOT</version> 15 <name>webapi Maven Webapp</name> 16 <url>http://maven.apache.org</url> 17 18 <dependencies> 19 <!--Module--> 20 <dependency> 21 <groupId>lm.solution</groupId> 22 <artifactId>service</artifactId> 23 <version>1.0-SNAPSHOT</version> 24 </dependency> 25 <dependency> 26 <groupId>lm.solution</groupId> 27 <artifactId>common</artifactId> 28 <version>1.0-SNAPSHOT</version> 29 </dependency> 30 31 <!--Libary--> 32 <dependency> 33 <groupId>cglib</groupId> 34 <artifactId>cglib</artifactId> 35 </dependency> 36 37 <!--mybatis spring 插件 --> 38 <dependency> 39 <groupId>org.mybatis</groupId> 40 <artifactId>mybatis-spring</artifactId> 41 </dependency> 42 <dependency> 43 <groupId>javax.servlet</groupId> 44 <artifactId>javax.servlet-api</artifactId> 45 <scope>provided</scope> 46 </dependency> 47 <dependency> 48 <groupId>javax.servlet.jsp</groupId> 49 <artifactId>jsp-api</artifactId> 50 <scope>provided</scope> 51 </dependency> 52 <dependency> 53 <groupId>javax.servlet</groupId> 54 <artifactId>jstl</artifactId> 55 </dependency> 56 <!-- 映入JSON lib --> 57 <dependency> 58 <groupId>net.sf.json-lib</groupId> 59 <artifactId>json-lib</artifactId> 60 <classifier>jdk15</classifier> 61 </dependency> 62 <!-- 用dom4j解析xml文件 --> 63 <dependency> 64 <groupId>dom4j</groupId> 65 <artifactId>dom4j</artifactId> 66 </dependency> 67 <!-- ehcache --> 68 <dependency> 69 <groupId>net.sf.ehcache</groupId> 70 <artifactId>ehcache-core</artifactId> 71 </dependency> 72 <dependency> 73 <groupId>net.sf.ehcache</groupId> 74 <artifactId>ehcache-web</artifactId> 75 </dependency> 76 <!-- 上传组件包 --> 77 <dependency> 78 <groupId>commons-fileupload</groupId> 79 <artifactId>commons-fileupload</artifactId> 80 </dependency> 81 <dependency> 82 <groupId>commons-io</groupId> 83 <artifactId>commons-io</artifactId> 84 </dependency> 85 <dependency> 86 <groupId>commons-codec</groupId> 87 <artifactId>commons-codec</artifactId> 88 </dependency> 89 <dependency> 90 <groupId>org.apache.commons</groupId> 91 <artifactId>commons-collections4</artifactId> 92 </dependency> 93 <dependency> 94 <groupId>org.apache.commons</groupId> 95 <artifactId>commons-lang3</artifactId> 96 </dependency> 97 <!-- commons-beanutils --> 98 <dependency> 99 <groupId>commons-beanutils</groupId> 100 <artifactId>commons-beanutils</artifactId> 101 <exclusions> 102 <exclusion> 103 <groupId>commons-logging</groupId> 104 <artifactId>commons-logging</artifactId> 105 </exclusion> 106 </exclusions> 107 </dependency> 108 <!-- freemarker --> 109 <dependency> 110 <groupId>org.freemarker</groupId> 111 <artifactId>freemarker</artifactId> 112 </dependency> 113 114 </dependencies> 115 116 <build> 117 <finalName>webapi</finalName> 118 119 <plugins> 120 <plugin> 121 <groupId>org.apache.tomcat.maven</groupId> 122 <artifactId>tomcat8-maven-plugin</artifactId> 123 </plugin> 124 </plugins> 125 </build> 126 </project>
9.webservice/pom.xml
这个模块是做为 JAX-WS 服务站点的。
重复内容不在讲解,参考上文的说明。
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>solution</artifactId> 5 <groupId>lm.solution</groupId> 6 <version>1.0-SNAPSHOT</version> 7 </parent> 8 <modelVersion>4.0.0</modelVersion> 9 10 <groupId>lm.solution</groupId> 11 <artifactId>webservice</artifactId> 12 <version>1.0-SNAPSHOT</version> 13 <packaging>war</packaging> 14 15 <name>webservice Maven Webapp</name> 16 <url>http://maven.apache.org</url> 17 18 <dependencies> 19 <!-- Module --> 20 <dependency> 21 <groupId>lm.solution</groupId> 22 <artifactId>service</artifactId> 23 <version>1.0-SNAPSHOT</version> 24 </dependency> 25 26 <!-- Libary --> 27 <dependency> 28 <groupId>com.sun.xml.ws</groupId> 29 <artifactId>jaxws-rt</artifactId> 30 </dependency> 31 </dependencies> 32 33 <build> 34 <finalName>webservice</finalName> 35 </build> 36 </project>
蒙
2018-05-25 23:36 周五
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- eclipse下创建Maven项目(包含webapp目录结构) 2020-06-09
- Maven安装与配置 2020-06-09
- Spring Cloud微服务(一):公共模块的搭建 2020-06-07
- IDEA下Maven的pom文件导入依赖出现Auto build completed wit 2020-06-07
- 解决IDEA Maven下载依赖包速度慢问题 2020-06-05
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash