1. 子pom.xml(包括总pom.xml和/dao/service/web三个层的pom.xml文件)依赖父pom.xml配置如下:
1 <parent> 2 <artifactId>xxxx</artifactId> 3 <groupId>xxxx</groupId> 4 <version>1.0.0-SNAPSHOT</version> 5 <relativePath>../../pom.xml</relativePath> 6 </parent>
2. 父pom.xml文件详解,切记这里一定在建立模块后,设置maven的setting.xml和.repotory文件
part1: 和常用的pom.xml文件类似配置
1 <modelVersion>4.0.0</modelVersion> 2 <groupId>xxxxx</groupId> 3 <artifactId>template-parent</artifactId> 4 <version>xxxxx-RELEASE</version> 5 <packaging>pom</packaging>
part2:版本设置
1 <properties> 2 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 3 <maven.build.timestamp.format>yyyyMMdd</maven.build.timestamp.format> 4 <compiler.source>1.7</compiler.source> 5 <compiler.target>1.7</compiler.target> 6 <spring.version>4.1.6.RELEASE</spring.version> 7 <slf4j.version>1.7.21</slf4j.version> 8 <log4j.version>1.2.17</log4j.version> 9 <logback-classic.version>1.1.7</logback-classic.version> 10 <shiro.version>1.2.4</shiro.version> 11 <commons-lang3.version>3.4</commons-lang3.version> 12 <commons-collections.version>3.2.1</commons-collections.version> 13 <commons-io.version>2.4</commons-io.version> 14 <commons-beanutils.version>1.9.2</commons-beanutils.version> 15 <commons-codec.version>1.10</commons-codec.version> 16 <httpclient.version>4.5.2</httpclient.version> 17 <jackson-core.version>2.7.9</jackson-core.version> 18 <jackson-databind.version>2.7.9.1</jackson-databind.version> 19 <fastjson.version>1.2.29</fastjson.version> 20 <jstl.version>1.2</jstl.version> 21 <standard.version>1.1.2</standard.version> 22 <servlet-api.version>2.5</servlet-api.version> 23 <junit.version>4.12</junit.version> 24 <quartz.version>2.2.3</quartz.version> 25 <mysql.version>5.1.38</mysql.version> 26 <mybatis.version>3.3.0</mybatis.version> 27 <mybatis-spring.version>1.2.3</mybatis-spring.version> 28 <jedis.version>2.8.1</jedis.version> 29 <ehcache.version>2.6.8</ehcache.version> 30 <!--<xxxx-commons.version>2.0.0.20170303-RELEASE</xxxx-commons.version> 31 <xxxx-mybatis.version>2.0.1.20170315-RELEASE</xxxx-mybatis.version> 32 <xxxx-redis.version>2.0.0.20170224-RELEASE</xxxx-redis.version> 33 <xxxx-properties.version>2.0.0.20170309-RELEASE</xxxx-properties.version>--> 34 <!--<xxxx-framework.version>2.1.0.20170319-RELEASE</xxxx-framework.version>--> 35 <dubbo.version>3.0.0-xxxx</dubbo.version> 36 <!--<xxxx.auth.version>3.0.0-RELEASE</xxxx.auth.version>--> 37 <curator.version>2.10.0</curator.version> 38 <zookeeper.version>3.4.6</zookeeper.version> 39 <zkclient.version>0.7</zkclient.version> 40 <netty.version>4.0.23.Final</netty.version> 41 <c3p0.version>0.9.1.2</c3p0.version> 42 <hibernate.validator>5.2.4.Final</hibernate.validator> 43 <javax.el.version>3.0.0</javax.el.version> 44 <guava.version>18.0</guava.version> 45 </properties>
part3:设置模块依赖
1.spring框架依赖:
1 <!--spring start --> 2 <dependency> 3 <groupId>org.springframework</groupId> 4 <artifactId>spring-core</artifactId> 5 <version>${spring.version}</version> 6 </dependency> 7 <dependency> 8 <groupId>org.springframework</groupId> 9 <artifactId>spring-beans</artifactId> 10 <version>${spring.version}</version> 11 </dependency> 12 <dependency> 13 <groupId>org.springframework</groupId> 14 <artifactId>spring-context</artifactId> 15 <version>${spring.version}</version> 16 </dependency> 17 <dependency> 18 <groupId>org.springframework</groupId> 19 <artifactId>spring-context-support</artifactId> 20 <version>${spring.version}</version> 21 </dependency> 22 <dependency> 23 <groupId>org.springframework</groupId> 24 <artifactId>spring-aop</artifactId> 25 <version>${spring.version}</version> 26 </dependency> 27 <dependency> 28 <groupId>org.springframework</groupId> 29 <artifactId>spring-aspects</artifactId> 30 <version>${spring.version}</version> 31 </dependency> 32 <dependency> 33 <groupId>org.springframework</groupId> 34 <artifactId>spring-expression</artifactId> 35 <version>${spring.version}</version> 36 </dependency> 37 <dependency> 38 <groupId>org.springframework</groupId> 39 <artifactId>spring-tx</artifactId> 40 <version>${spring.version}</version> 41 </dependency> 42 <dependency> 43 <groupId>org.springframework</groupId> 44 <artifactId>spring-test</artifactId> 45 <version>${spring.version}</version> 46 </dependency> 47 <dependency> 48 <groupId>org.springframework</groupId> 49 <artifactId>spring-jdbc</artifactId> 50 <version>${spring.version}</version> 51 </dependency> 52 <dependency> 53 <groupId>org.springframework</groupId> 54 <artifactId>spring-web</artifactId> 55 <version>${spring.version}</version> 56 </dependency> 57 58 <dependency> 59 <groupId>org.springframework</groupId> 60 <artifactId>spring-webmvc</artifactId> 61 <version>${spring.version}</version> 62 </dependency> 63 <!--spring end -->
2. common组件:
1 <!--common start --> 2 <dependency> 3 <groupId>org.apache.commons</groupId> 4 <artifactId>commons-lang3</artifactId> 5 <version>${commons-lang3.version}</version> 6 </dependency> 7 <dependency> 8 <groupId>commons-collections</groupId> 9 <artifactId>commons-collections</artifactId> 10 <version>${commons-collections.version}</version> 11 </dependency> 12 <dependency> 13 <groupId>commons-io</groupId> 14 <artifactId>commons-io</artifactId> 15 <version>${commons-io.version}</version> 16 </dependency> 17 <dependency> 18 <groupId>commons-codec</groupId> 19 <artifactId>commons-codec</artifactId> 20 <version>${commons-codec.version}</version> 21 </dependency> 22 <dependency> 23 <groupId>commons-beanutils</groupId> 24 <artifactId>commons-beanutils</artifactId> 25 <version>${commons-beanutils.version}</version> 26 </dependency> 27 <dependency> 28 <groupId>org.apache.httpcomponents</groupId> 29 <artifactId>httpclient</artifactId> 30 <version>${httpclient.version}</version> 31 </dependency> 32 33 <!--common end -->
3. JSON
1 <!-- json start --> 2 <dependency> 3 <groupId>com.fasterxml.jackson.core</groupId> 4 <artifactId>jackson-core</artifactId> 5 <version>${jackson-core.version}</version> 6 </dependency> 7 <dependency> 8 <groupId>com.fasterxml.jackson.core</groupId> 9 <artifactId>jackson-databind</artifactId> 10 <version>${jackson-databind.version}</version> 11 </dependency> 12 <dependency> 13 <groupId>com.alibaba</groupId> 14 <artifactId>fastjson</artifactId> 15 <version>${fastjson.version}</version> 16 </dependency> 17 <!-- json end -->
4.JSTL表达式语言
1 <dependency> 2 <groupId>jstl</groupId> 3 <artifactId>jstl</artifactId> 4 <version>${jstl.version}</version> 5 </dependency> 6 <dependency> 7 <groupId>taglibs</groupId> 8 <artifactId>standard</artifactId> 9 <version>${standard.version}</version> 10 </dependency>
5.servlet-api
1 <dependency> 2 <groupId>javax.servlet</groupId> 3 <artifactId>servlet-api</artifactId> 4 <version>${servlet-api.version}</version> 5 </dependency>
6.日志log
1 <dependency> 2 <groupId>ch.qos.logback</groupId> 3 <artifactId>logback-classic</artifactId> 4 <version>${logback-classic.version}</version> 5 </dependency> 6 <!-- common-logging 实际调用slf4j --> 7 <dependency> 8 <groupId>org.slf4j</groupId> 9 <artifactId>jcl-over-slf4j</artifactId> 10 <version>${slf4j.version}</version> 11 </dependency> 12 <!-- java.util.logging 实际调用slf4j --> 13 <dependency> 14 <groupId>org.slf4j</groupId> 15 <artifactId>jul-to-slf4j</artifactId> 16 <version>${slf4j.version}</version> 17 </dependency> 18 <dependency> 19 <groupId>org.slf4j</groupId> 20 <artifactId>log4j-over-slf4j</artifactId> 21 <version>${slf4j.version}</version> 22 </dependency> 23 <dependency> 24 <groupId>org.slf4j</groupId> 25 <artifactId>slf4j-log4j12</artifactId> 26 <version>${slf4j.version}</version> 27 </dependency> 28 <dependency> 29 <groupId>log4j</groupId> 30 <artifactId>log4j</artifactId> 31 <version>${log4j.version}</version> 32 </dependency>
7.公司的四大依赖
8. 分布式
1 <dependency> 2 <groupId>com.alibaba</groupId> 3 <artifactId>dubbo</artifactId> 4 <version>${dubbo.version}</version> 5 <exclusions> 6 <exclusion> 7 <groupId>org.apache.httpcomponents</groupId> 8 <artifactId>httpcore</artifactId> 9 </exclusion> 10 <exclusion> 11 <groupId>com.google.guava</groupId> 12 <artifactId>guava</artifactId> 13 </exclusion> 14 <exclusion> 15 <artifactId>curator-client</artifactId> 16 <groupId>org.apache.curator</groupId> 17 </exclusion> 18 </exclusions> 19 </dependency>
9. 安全性
1 <!-- SECURITY begin --> 2 <dependency> 3 <groupId>org.apache.shiro</groupId> 4 <artifactId>shiro-core</artifactId> 5 <version>${shiro.version}</version> 6 </dependency> 7 <dependency> 8 <groupId>org.apache.shiro</groupId> 9 <artifactId>shiro-spring</artifactId> 10 <version>${shiro.version}</version> 11 </dependency> 12 <dependency> 13 <groupId>org.apache.shiro</groupId> 14 <artifactId>shiro-cas</artifactId> 15 <version>${shiro.version}</version> 16 <exclusions> 17 <exclusion> 18 <groupId>commons-logging</groupId> 19 <artifactId>commons-logging</artifactId> 20 </exclusion> 21 </exclusions> 22 </dependency> 23 <dependency> 24 <groupId>org.apache.shiro</groupId> 25 <artifactId>shiro-web</artifactId> 26 <version>${shiro.version}</version> 27 </dependency> 28 <dependency> 29 <groupId>org.apache.shiro</groupId> 30 <artifactId>shiro-ehcache</artifactId> 31 <version>${shiro.version}</version> 32 </dependency> 33 <!-- <dependency> 34 <groupId>xxxx</groupId> 35 <artifactId>xxx.xxxxx.xxxx.auth</artifactId> 36 <version>${xxxx.auth.version}</version> 37 <exclusions> 38 <exclusion> 39 <groupId>log4j</groupId> 40 <artifactId>log4j</artifactId> 41 </exclusion> 42 <exclusion> 43 <groupId>org.slf4j</groupId> 44 <artifactId>slf4j-log4j12</artifactId> 45 </exclusion> 46 </exclusions> 47 </dependency>--> 48 <!-- SECURITY end -->
10. zookeeper
1 <!-- zk --> 2 <dependency> 3 <groupId>org.apache.curator</groupId> 4 <artifactId>curator-framework</artifactId> 5 <version>${curator.version}</version> 6 </dependency> 7 <dependency> 8 <groupId>org.apache.curator</groupId> 9 <artifactId>curator-recipes</artifactId> 10 <version>${curator.version}</version> 11 </dependency> 12 <dependency> 13 <groupId>org.apache.zookeeper</groupId> 14 <artifactId>zookeeper</artifactId> 15 <version>${zookeeper.version}</version> 16 <exclusions> 17 <exclusion> 18 <artifactId>log4j</artifactId> 19 <groupId>log4j</groupId> 20 </exclusion> 21 <exclusion> 22 <groupId>org.slf4j</groupId> 23 <artifactId>slf4j-log4j12</artifactId> 24 </exclusion> 25 </exclusions> 26 </dependency> 27 <dependency> 28 <groupId>com.101tec</groupId> 29 <artifactId>zkclient</artifactId> 30 <version>${zkclient.version}</version> 31 <exclusions> 32 <exclusion> 33 <artifactId>log4j</artifactId> 34 <groupId>log4j</groupId> 35 </exclusion> 36 <exclusion> 37 <groupId>org.slf4j</groupId> 38 <artifactId>slf4j-log4j12</artifactId> 39 </exclusion> 40 </exclusions> 41 </dependency>
11. netty
1 <dependency> 2 <groupId>io.netty</groupId> 3 <artifactId>netty-all</artifactId> 4 <version>${netty.version}</version> 5 </dependency>
12.hibernate
1 <dependency> 2 <groupId>org.hibernate</groupId> 3 <artifactId>hibernate-validator</artifactId> 4 <version>${hibernate.validator}</version> 5 </dependency>
13. guava:Guava是一种基于开源的Java库,其中包含谷歌正在由他们很多项目使用的很多核心库
1 <dependency> 2 <groupId>com.google.guava</groupId> 3 <artifactId>guava</artifactId> 4 <version>${guava.version}</version> 5 </dependency>