Maven

一、  Maven

1.  Maven 简介

1. Maven 是一个项目管理和整合工具,依赖 JDK。由 Apache 小组开发,主要目的是为开发者提供一个可复用、可维护、更易理解的项目综合模型
下载地址:https://maven.apache.org/download.cgi
2. Maven 是基于 POM(Project Object Model,即:项目对象模型)概念的,通过一个中央信息管理模块,Maven 能够管理项目的构建、报告和文档 3. Maven 的优点: 1)Maven 简化了项目的构建过程,并对其标准化 2)Maven 能够实现同时构建多个项目、发布项目信息、部署项目、在几个项目中共享 JAR 文件,并且协助团队合作 3)Maven 提高了重用性 4. Maven 项目结构和内容被定义在 pom.xml 文件中,此文件是整个 Maven 系统的基础组件 5. Maven 使用约定而不是配置,为开发者提供了选项来配置项目依赖(依赖于 Maven 的插件扩展功能和默认的约定)

2.  Maven 仓库

1. Maven 仓库是一个位置(place),可以存储所有的项目 jar 文件、library jar 文件、插件和其他的项目文件
2. Maven 仓库有三种类型:
1)本地仓库(local)
a. Maven 本地仓库是机器上的一个文件夹,文件夹路径由自己在 settings.xml 中配置
b. Maven 本地仓库保存你的项目的所有依赖(library jar、plugin jar 等)
c. 第一次运行 Maven 命令,Maven 会从中央仓库中自动下载所有依赖的 jar 文件到本地仓库中
d. 由于地域问题,从中央仓库的默认镜像下载依赖文件速度慢,所以我们常在 settings.xml 中配置国内镜像

2)中央仓库(central)
a. Maven 中央仓库是由 Maven 社区提供的仓库,其中包含了大量常用的库
b. 由 Maven 社区管理,不需要配置,需要通过网络才能访问
c. Maven 社区提供了一个用于浏览中央仓库内容的 URL :https://search.maven.org/

3)远程仓库(remote)
a. 如果 Maven 在中央仓库中也找不到依赖的库文件,它会停止构建过程并输出错误信息到控制台
b. 为避免这种情况,Maven 提供了远程仓库的概念,它是开发人员自己定制仓库,包含了所需要的代码库或者其他项目中用到的 jar 文件

3. Maven 依赖搜索顺序
1)在本地仓库中搜索,如果找不到,执行步骤 2
2)在中央仓库中搜索,如果找到则下载到本地仓库;如果找不到,并且有一个或多个远程仓库已经设置,则执行步骤 3
3)在一个或多个远程仓库中搜索,如果找到则下载到本地仓库,否则 Maven 将停止处理并抛出错误(无法找到依赖的文件)

4. 配置 Mavenapache-maven-3.5.4conf 目录下的 settings.xml 如下:
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <localRepository>D:/maven/localRepository</localRepository>

  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
      <mirror>
          <id>alimaven</id>
          <name>aliyun maven</name>
          <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
          <mirrorOf>central</mirrorOf>        
      </mirror>
  </mirrors>

  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.4</id>

      <activation>
        <jdk>1.4</jdk>
      </activation>

      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->

    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>

      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>

      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
        
    <profile>
        <id>jdk-1.8</id>  
        <activation>  
          <activeByDefault>true</activeByDefault>  
          <jdk>1.8</jdk>  
        </activation>
        <properties>
            <maven.compiler.source>1.8</maven.compiler.source>  
            <maven.compiler.target>1.8</maven.compiler.target>  
            <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
        </properties>
    </profile>
        
  </profiles>

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>
settings.xml

3.  Maven POM

1. POM 是使用 Maven 工作时的基本组建,是一个 xml 文件,它被放在项目根目录下,文件命名为 pom.xml
2. POM 包含了关于项目和各种配置细节的信息,每个项目只有一个 POM 文件
3. 所有的 POM 文件需要 project 元素和三个必须的字段:groupIdartifactIdversion,如:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ncdx</groupId> <artifactId>ssm</artifactId> <version>0.0.1-SNAPSHOT</version> </project>

4. 坐标
1)每个 jar 文件都有一个唯一坐标,通过坐标可以精确指定是哪个 jar
2)坐标组成:dependencygroupIdartifactIdversion
<dependency>
<groupId>
org.springframework</groupId>
<artifactId>
spring-webmvc</artifactId>
<version>
${spring-version}</version>
</dependency>

3)可通过该网址查找坐标:https://mvnrepository.com/

4.  Eclipse 创建 Maven 项目(jar 类型)

1. New Maven Project

2. 勾选复选框,创建一个简单 Maven 项目(不应用任何模板)

3. 填写项目信息
1)Grope Id
2)Artifact Id
3)Version
4)Packaging: a. jar :普通 Java 项目 b. war :Web 项目 c. pom :逻辑父项目,只要一个项目中有子项目那必须指定 pom 类型

4. Finish ,Maven 会创建默认的项目结构,开发者只需要合理的放置文件,项目层次结构如图所示:
1)src/main/java :快捷目录,编写 Java 代码
2)src/main/resources :快捷目录,编写配置文件
3)src/test/java :编写测试代码
4)src/text/resources :编写测试的配置文件
5)pom.xml :当前项目所依赖的其他项目、jar或插件等

5.  Maven 项目之间的关系

1. 依赖关系
   1)标签 <dependency> 把另一个项目的 jar 引入到当前项目
   2)自动下载另一个项目所依赖的其他项目
<dependency>
<groupId>
com.ncdx</groupId>
<artifactId>
commons</artifactId>
<version>
0.0.1-SNAPSHOT</version>
</dependency>

2. 继承关系 1)父项目是 pom 类型 2)子项目可以是 jar、war 或 pom 类型 3)有继承关系后,子项目的 pom.xml 中出现
<parent> 标签 a. 如果子项目的 <groupId> <version> 与父项目的相同,在子项目中可以不配置 <groupId> <version>
<parent> <groupId>com.ncdx</groupId> <artifactId>parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent>
4)父项目中不包含子项目,在逻辑上具有父子项目关系
3. 聚合关系 1)前提是继承关系,父项目会把子项目包含到父项目中 2)子项目的类型必须是 Maven Module 而不是 Maven Project 3)新建聚合项目的子项目时,点击父项目右键新建 Maven Module 4)具有聚合关系的父项目,在 pom.xml 中出现
<modules> 标签 <modules> <module>commons</module>
<module>
pojo</module>
<module>service</module> </modules> 5)具有聚合关系的子项目,在 pom.xml 中出现 <parent> 标签 <parent> <groupId>com.ncdx</groupId> <artifactId>parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> 4. 聚合项目和继承项目区别 1)在语意上聚合关系的父项目和子项目关系性较强,继承关系的父项目和子项目关系性较弱 5. <dependencyManagement> 写在父项目 1)作用:声明可能使用到的所有 jar 2)子项目中只需要有坐标的 <groupid> <artifactid> <version> 继承父项目 3)在父项目中 <properties> 把所有版本号进行统一管理 a. <properties> 子标签名称自定义 b. ${} 引用标签的值
c. 例如
父项目 pom.xml 中:
<properties> <spring-version>4.1.6.RELEASE</spring-version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring-version}</version> </dependency> </dependencies> </dependencyManagement> 子项目 pom.xml <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> </dependencies>

6.  Eclipse 创建 Maven 项目(war 类型)

1. 在创建 Maven Project 时选择 packaging 为 war
2. 在 src/main/webapp 文件夹下新建 META-INFWEB-INF/web.xml
3. 在 pom.xml 中添加 Java EE 相关的 3 个 jar 的坐标:
   <dependencies>
     <!-- javaEE -->
     <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>${servlet-version}</version>
      <scope>provided</scope> // 有效范围 provided 表示编译期生效,不会打包发布到 Tomcat 中
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>javax.servlet.jsp-api</artifactId>
      <version>${jsp-version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>${jstl-version}</version>
    </dependency>
   </dependencies>

4. 配置 Tomcat 插件:
   <build>
    <pluginManagement> 
     <plugins>
       <plugin>
         <groupId>org.apache.tomcat.maven</groupId>
         <artifactId>tomcat7-maven-plugin</artifactId>
         <version>2.2</version>
         <configuration>
           <port>80</port>
           <path>/</path>
<!-- 热部署
1. 修改 tomat/conf/tomcat-users.xml 添加
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="tomcat" password="tomcat" roles="manager-gui,manager-script"/>

2. 在 pom.xml 中 tomcat 插件的 <configuration> 里配置

<username>tomcat</username>
<password>tomcat</password>
<url>http://192.168.48.130:8080/manager/text</url>

3. 右键项目--> run as --> maven build --> Goals 中输入 tomcat7:deploy
tomcat7:redeploy
--> </configuration> </plugin> </plugins> </pluginManagement> </build> 5. 右键项目 --> run as --> maven build--> Goals 中输入 clean tomcat7:run

7.  自定义资源拷贝

1. Maven 默认只把 src/main/java 下的 java 文件编辑到 classes 中
2.
Maven 默认只把 src/main/resources 里面的非 java 文件进行编译到 classes 中
3. 通过配置 pom.xml 可以实现自己的需求

<
build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.xml</include> <include>**/*.properties</include> </includes> </resource> </resources> </build>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.ego</groupId>
  <artifactId>ego-parent</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
 
  <properties>
    <servlet-version>3.1.0</servlet-version>
    <jsp-version>2.3.1</jsp-version>
    <jstl-version>1.2</jstl-version>
    <springmvc-version>5.1.1.RELEASE</springmvc-version>
    <springJDBC-version>5.1.1.RELEASE</springJDBC-version>
    <aspectjweaver-version>1.9.1</aspectjweaver-version>
    <mybatis-version>3.4.5</mybatis-version>
    <mybatis-spring-version>1.3.1</mybatis-spring-version>
    <log4j-version>1.2.17</log4j-version>
    <mysql-connector-java-version>5.1.47</mysql-connector-java-version>
    <jackson-version>2.9.6</jackson-version>
    <commons-fileupload-version>1.3.1</commons-fileupload-version>
    <dubbo-version>2.5.3</dubbo-version>
    <zookeeper-client-version>0.10</zookeeper-client-version>
    <ftpclient-version>3.3</ftpclient-version>
    <jedis-version>2.8.1</jedis-version>
    <tomcat-version>2.2</tomcat-version>
    <pagehelper-version>4.1.6</pagehelper-version>
    <solrJ-version>5.3.1</solrJ-version>
    <httpclient-version>4.4.1</httpclient-version>
  </properties>
  <dependencyManagement>
      <dependencies>
         <!-- javaEE -->
         <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>${servlet-version}</version>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>javax.servlet.jsp</groupId>
          <artifactId>javax.servlet.jsp-api</artifactId>
          <version>${jsp-version}</version>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>jstl</groupId>
          <artifactId>jstl</artifactId>
          <version>${jstl-version}</version>
        </dependency>
        <!-- spring -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
          <version>${springmvc-version}</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-jdbc</artifactId>
          <version>${springJDBC-version}</version>
        </dependency>
        <dependency>
          <groupId>org.aspectj</groupId>
          <artifactId>aspectjweaver</artifactId>
          <version>${aspectjweaver-version}</version>
        </dependency>
       
        <!-- mybatis -->
        <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis</artifactId>
          <version>${mybatis-version}</version>
        </dependency>
        <!-- mybatis和spring整合 -->
        <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis-spring</artifactId>
          <version>${mybatis-spring-version}</version>
        </dependency>
        <!-- 日志包 -->
        <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
          <version>${log4j-version}</version>
        </dependency>
        <!-- mysql驱动 -->
        <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>${mysql-connector-java-version}</version>
        </dependency>
        <!-- jackson -->
        <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-databind</artifactId>
          <version>${jackson-version}</version>
        </dependency>
        <!-- fileupload -->
        <dependency>
          <groupId>commons-fileupload</groupId>
          <artifactId>commons-fileupload</artifactId>
          <version>${commons-fileupload-version}</version>
        </dependency>
        
        <!-- dubbo -->
        <dependency>
          <groupId>com.alibaba</groupId>
          <artifactId>dubbo</artifactId>
          <version>${dubbo-version}</version>
          <exclusions>
            <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
            </exclusion>
          </exclusions>
        </dependency>

        <!-- 访问zookeeper客户端的jar -->
        <dependency>
          <groupId>com.101tec</groupId>
          <artifactId>zkclient</artifactId>
          <version>${zookeeper-client-version}</version>
        </dependency>
        
        <!-- ftpclient -->
        <dependency>
          <groupId>commons-net</groupId>
          <artifactId>commons-net</artifactId>
          <version>${ftpclient-version}</version>
        </dependency>
        
        <!-- jedis -->
        <dependency>
          <groupId>redis.clients</groupId>
          <artifactId>jedis</artifactId>
          <version>${jedis-version}</version>
        </dependency> 
        
        <!-- mybatis分页插件 -->
        <dependency>
          <groupId>com.github.pagehelper</groupId>
          <artifactId>pagehelper</artifactId>
          <version>${pagehelper-version}</version>
        </dependency>
        
        <!-- solrJ -->
        <dependency>
          <groupId>org.apache.solr</groupId>
          <artifactId>solr-solrj</artifactId>
          <version>${solrJ-version}</version>
        </dependency>
        
        <!-- httpclient -->
        <dependency>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpclient</artifactId>
          <version>${httpclient-version}</version>
        </dependency>
      </dependencies>
  </dependencyManagement>
 
    <build>
      <!-- 资源 -->
      <resources>
        <resource>
          <directory>src/main/java</directory>
            <includes>
              <include>**/*.xml</include>
            </includes>
         </resource>
         <resource>
          <directory>src/main/resources</directory>
            <includes>
              <include>**/*.xml</include>
              <include>**/*.properties</include>
            </includes>
         </resource>
       </resources>     
       
       <!-- Tomcat7 -->   
       <pluginManagement> 
        <plugins>
          <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>${tomcat-version}</version>
            <configuration>
              <port>80</port>
              <path>/</path>
            </configuration>
          </plugin>
        </plugins>
       </pluginManagement>  
      </build>
    <modules>
        <module>ego-pojo</module>
        <module>ego-service</module>
        <module>ego-service-impl</module>
        <module>ego-commons</module>
        <module>ego-manage</module>
        <module>ego-portal</module>
        <module>ego-item</module>
        <module>ego-redis</module>
        <module>ego-search</module>
        <module>ego-passport</module>
        <module>ego-cart</module>
        <module>ego-order</module>
    </modules>
</project>
pom.xml
原文地址:https://www.cnblogs.com/IT-LFP/p/11842176.html