• 使用Maven进行依赖管理和项目构建


    什么是Maven

    1 依赖的管理:仅仅通过jar包的几个属性,就能确定唯一的jar包,在指定的文件pom.xml中,只要写入这些依赖属性,就会自动下载并管理jar包。
    2 项目的构建:内置很多的插件与生命周期,支持多种任务,比如校验、编译、测试、打包、部署、发布...
    3 项目的知识管理:管理项目相关的其他内容,比如开发者信息,版本等等 

    官网:http://maven.apache.org/

    Maven库:http://repo2.maven.org/maven2/ 

    中央仓库资源:http://mvnrepository.com/

    下载安装

     去maven的官网上下载,http://maven.apache.org/download.cgi,根据自己电脑的实际情况选择对应的文件。

    下载完毕后将其解压到任意位置,例如我的电脑上就是D:mavenapache-maven-3.2.5

    Maven环境配置

    注意:安装maven之前,必须先确保你的机器中已经安装了JDK,如果是Maven3则必须JDK1.7以上。

    1.解压压缩包

    2.添加环境变量MAVEN_HOME,值为apache-maven的安装路径:D:mavenapache-maven-3.2.5

    3.在Path环境变量的变量值末尾添加%MAVEN_HOME%in;

    4.在cmd输入mvn –version,如果出现maven的版本信息,说明配置成功。

     

     

    本地仓储配置

     如果您不配置,默认会在如下位置存放从远程下载到的包:

    从中央仓库下载的jar包,都会统一存放到本地仓库中。我们需要配置本地仓库的位置。

    打开maven安装目录,打开conf目录下的setting.xml文件。

    可以参照下图配置本地仓储位置。

    修改默认中央仓库地址:D:MavenResponse

    Ecplise使用Maven

    1.插件安装

    依次选择Eclipse菜单栏的“Help”菜单à“Instance NewSoftWare”菜单项,就会弹出如下对话窗口:

    ,然后点击add按钮,会出现一个对话框,这个对话框就是用于添加一个插件地址的。在“Name”对应的输入框里输入该操作的一个标识名。在“Location”对应的输入框里输入这个插件的安装地址。注:Maven的Eclipse插件地址为:http://download.eclipse.org/technology/m2e/releases。输入后,如下图所示:

     2.Ecplise配置maven

    Maven常用的命令

    以下所有的命令都要在项目的根目录下进行。
    Maven提供了一套命令,我们可以在dos小黑窗中使用,当对Maven项目使用这些命令的时候我们应该切换到该项目的根目录下。
    命令一:
    mvn clean
    这个命令可以清除我们的target文件夹(这个文件夹存放编译后的.class文件)

    命令二:
    mvn compile
    和上面的命令相反,这个命令是编译一个项目的,前提是我们当前命令行位置为该项目的根目录下。

    命令三:
    mvn test
    这个命令可以进行单元测试,测试test文件夹下的方法(test文件夹下的java文件格式名为:XxxTest.java)

    命令四:
    mvn package
    将项目打包,如果是java项目就打包为.jar文件,如果是web项目及打包成.war文件。

    命令五:
    mvn install
    将一个项目打包放在本地仓库中,以便多个项目使用。

     

    创建Maven项目容易出现的问题

    Maven的常规使用

    1.设置全局的jdk,在setting.xml文件中的profiles元素下添加如下profile元素:

    <profile>  
        <id>jdk17</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> 
    View Code

    2.设置局部的jdk,在项目的pom,xml文件中添加如下build元素:

    <build>  
        <plugins>  
            <plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-compiler-plugin</artifactId>  
                <configuration>  
                    <source>1.8</source>  
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>  
                </configuration>  
            </plugin>  
        </plugins>  
    </build>  
    View Code

    3.添加依赖

    我们在Maven项目中创建一个Servlet,我们需要导入servlet-api.jar,只要在pom.xml 的dependencies视图下进行add就好了。

    4.依赖范围

    在我们设置依赖的时候,会有一项Scope,里面有:
    compile,provided,runtime,test,system五项。
    这里写图片描述
    (图片来自网络)

    Maven默认的是compile,即对于编译classpath,测试classpath,运行时classpath 都需要这个jar包。
    尤其值得注意的是provided,这个就像servlet-api那样,我们编译测试都需要这个jar包,但是当上传到服务器的时候就不再需要了(Tomcat的lib下有),如果这里我们默认compile,那么当程序在服务器上运行的时候将出现jar包的冲突!

    5.Maven工程的多模块项目、项目与项目之间的引用

      1)父项目  

    <?xml version="1.0" encoding="UTF-8"?>
    <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.kamfu.ats.cw</groupId>
        <artifactId>cw-parent</artifactId>
        <version>20190807-RELEASE</version>
        <packaging>pom</packaging>
        <!-- 多模块配置:根据子模块的相互依赖关系整理一个build顺序,然后依次build -->
        <modules>
            <module>kf.ats.gvnsvr.client</module>
            <module>kf.ats.gvnsvr.base</module>
        </modules>
        <repositories>
            <repository>
                <id>public</id>
                <url>http://localhost:8081/nexus/content/groups/public/</url>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>public</id>
                <url>http://localhost:8081/nexus/content/groups/public/</url>
            </pluginRepository>
        </pluginRepositories>
        <properties>
            <ggywpt.version>20190807-RELEASE</ggywpt.version>
            <ywzcxt.version>20190807-RELEASE</ywzcxt.version>
            <jcpt.version>20190807-RELEASE</jcpt.version>
            <ats55.version>20190807-RELEASE</ats55.version>
            <sbglq.version>20190807-RELEASE</sbglq.version>
            <parent-version>20190807-RELEASE</parent-version>        
        </properties>
    
        <dependencies>
            <dependency>
              <groupId>com.spire</groupId>
              <artifactId>pdf</artifactId>
              <version>1.0</version>
            </dependency>     
    
            <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            </dependency>
            <!--<dependency>-->
                <!--<groupId>com.kamfu.ats.ywzcxt</groupId>-->
                <!--<artifactId>kf.ats.plt.supervisor.common</artifactId>-->
            <!--</dependency>-->
    
    
            <dependency>
                <groupId>commons-discovery</groupId>
                <artifactId>commons-discovery</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.mina</groupId>
                <artifactId>mina-core</artifactId>
            </dependency>
            <dependency>
                <groupId>commons-lang</groupId>
                <artifactId>commons-lang</artifactId>
            </dependency>
            <dependency>
                <groupId>net.sourceforge.htmlunit</groupId>
                <artifactId>htmlunit</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi-ooxml</artifactId>
            </dependency>
            <dependency>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.pdfbox</groupId>
                <artifactId>pdfbox</artifactId>
            </dependency>
            <dependency>
                <groupId>com.gd</groupId>
                <artifactId>gd-security</artifactId>
            </dependency>
            <dependency>
                <groupId>commons-beanutils</groupId>
                <artifactId>commons-beanutils-core</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.axis</groupId>
                <artifactId>axis</artifactId>
            </dependency>
            <dependency>
                <groupId>org.jsoup</groupId>
                <artifactId>jsoup</artifactId>
            </dependency>
            <dependency>
                <groupId>net.sf.json-lib</groupId>
                <artifactId>json-lib</artifactId>
                <classifier>jdk15</classifier>
            </dependency>
            <dependency>
                <groupId>com.cndatacom</groupId>
                <artifactId>commons-best</artifactId>
            </dependency>
            <dependency>
                <groupId>com.sybase</groupId>
                <artifactId>jconn3</artifactId>
            </dependency>
            <dependency>
                <groupId>javax.xml</groupId>
                <artifactId>jaxrpc</artifactId>
            </dependency>
            <dependency>
                <groupId>org.bouncycastle</groupId>
                <artifactId>bcprov-jdk15on</artifactId>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpmime</artifactId>
            </dependency>
            <dependency>
                <groupId>com.kamfu</groupId>
                <artifactId>kamfu-encrypt</artifactId>
            </dependency>
            <dependency>
                <groupId>com.lowagie</groupId>
                <artifactId>itext</artifactId>
            </dependency>
            <dependency>
                <groupId>com.gdca</groupId>
                <artifactId>pasp</artifactId>
            </dependency>
            <dependency>
                <groupId>org.jdom</groupId>
                <artifactId>jdom2</artifactId>
            </dependency>
        </dependencies>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>com.itextpdf</groupId>
                    <artifactId>itextpdf</artifactId>
                     <version>5.5.12</version>
                </dependency>
                <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <version>4.12</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.jdom</groupId>
                    <artifactId>jdom2</artifactId>
                    <version>2.0.6</version>
                </dependency>
                <dependency>
                    <groupId>com.gdca</groupId>
                    <artifactId>pasp</artifactId>
                    <version>1.0.0</version>
                </dependency>
                <dependency>
                    <groupId>com.lowagie</groupId>
                    <artifactId>itext</artifactId>
                    <version>2.0.6</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu</groupId>
                    <artifactId>kamfu-encrypt</artifactId>
                    <version>1.0.0</version>
                </dependency>
                
                <!-- jcpt -->      
                <dependency>
                    <groupId>com.kamfu.ats.jcpt</groupId>
                    <artifactId>jcpt-parent</artifactId>
                    <version>${jcpt.version}</version>
                    <type>pom</type>
                </dependency>                  
                <dependency>
                    <groupId>com.kamfu.ats.jcpt</groupId>
                    <artifactId>kf.ats.plt.resources</artifactId>
                    <version>${jcpt.version}</version>
                </dependency>            
                <dependency>
                    <groupId>com.kamfu.ats.jcpt</groupId>
                    <artifactId>kf.ats.plt.minisys.clientapp</artifactId>
                    <version>${jcpt.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.jcpt</groupId>
                    <artifactId>kf.ats.plt.base</artifactId>
                    <version>${jcpt.version}</version>
                </dependency>       
                <dependency>
                    <groupId>com.kamfu.ats.jcpt</groupId>
                    <artifactId>kf.ats.plt.base.extend</artifactId>
                    <version>${jcpt.version}</version>
                </dependency>                         
                <dependency>
                    <groupId>com.kamfu.ats.jcpt</groupId>
                    <artifactId>kf.ats.plt.core</artifactId>
                    <version>${jcpt.version}</version>
                </dependency>                     
                
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats55.platform</groupId> -->
    <!--                 <artifactId>kf.ats.plt.server.compatible</artifactId> -->
    <!--                 <version>20190807-RELEASE</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats55.platform</groupId> -->
    <!--                 <artifactId>kf.ats.plt.common.compatible</artifactId> -->
    <!--                 <version>0.0.1-20181003.071009-4</version> -->
    <!--             </dependency> -->
                
                
                <!-- ggywpt -->
                <dependency>
                    <groupId>com.kamfu.ats.ggywpt</groupId>
                    <artifactId>kf.ats.buss.front</artifactId>
                    <version>${ggywpt.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.ggywpt</groupId>
                    <artifactId>kf.ats.buss.back</artifactId>
                    <version>${ggywpt.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.ggywpt</groupId>
                    <artifactId>kf.ats.buss.common</artifactId>
                    <version>${ggywpt.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.ggywpt</groupId>
                    <artifactId>kf.ats.buss.common.extend</artifactId>
                    <version>${ggywpt.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.ggywpt</groupId>
                    <artifactId>kf.ats.buss.pay.weixin</artifactId>
                    <version>${ggywpt.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.ywzcxt</groupId>
                    <artifactId>kf.ats.oam.client</artifactId>
                   <version>${ggywpt.version}</version>
                </dependency>
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.ywzcxt</groupId> -->
    <!--                 <artifactId>kf.ats.plt.supervisor.web</artifactId> -->
    <!--                 <version>${ywzcxt.version}</version> -->
    <!--                 <type>war</type> -->
    <!--             </dependency> -->
                <dependency>
                    <groupId>com.kamfu.ats.ywzcxt</groupId>
                    <artifactId>kf.ats.plt.supervisor.common</artifactId>
                    <version>${ywzcxt.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.ywzcxt</groupId>
                    <artifactId>kf.ats.plt.supervisor.client</artifactId>
                    <version>${ywzcxt.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.ywzcxt</groupId>
                    <artifactId>kf.ats.plt.supervisor.server</artifactId>
                    <version>${ywzcxt.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.ywzcxt</groupId>
                    <artifactId>kf.ats.plt.supervisor.server.ui</artifactId>
                    <version>${ywzcxt.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.ywzcxt</groupId>
                    <artifactId>kf.ats.oam.server</artifactId>
                    <version>${ywzcxt.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.sbglq</groupId>
                    <artifactId>kf.ats.plt.client.base.extend</artifactId>
                    <version>${sbglq.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.sbglq</groupId>
                    <artifactId>kf.ats.plt.client.base</artifactId>
                    <version>${sbglq.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.jcpt</groupId>
                    <artifactId>kf.ats.plt.minisys.serverapp</artifactId>
                    <version>${jcpt.version}</version>
                    <exclusions>
                        <exclusion>
                            <groupId>javax.servlet</groupId>
                            <artifactId>servlet-api</artifactId>
                        </exclusion>
                        <exclusion>
                            <groupId>com.kamfu.ats.jcpt</groupId>
                            <artifactId>kf.ats.plt.minisys.pub</artifactId>
                        </exclusion>                    
                    </exclusions>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.jcpt</groupId>
                    <artifactId>kf.ats.plt.core.ui</artifactId>
                    <version>${jcpt.version}</version>
                    <type>jar</type>
                </dependency>
                <dependency>
                    <groupId>org.apache.mina</groupId>
                    <artifactId>mina-core</artifactId>
                    <version>2.0.4</version>
                </dependency>
                <dependency>
                    <groupId>commons-lang</groupId>
                    <artifactId>commons-lang</artifactId>
                    <version>2.6</version>
                </dependency>
                <dependency>
                    <groupId>net.sourceforge.htmlunit</groupId>
                    <artifactId>htmlunit</artifactId>
                    <version>2.4</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.poi</groupId>
                    <artifactId>poi</artifactId>
                    <version>3.12</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.poi</groupId>
                    <artifactId>poi-ooxml</artifactId>
                    <version>3.12</version>
                </dependency>
                <dependency>
                    <groupId>commons-codec</groupId>
                    <artifactId>commons-codec</artifactId>
                    <version>1.4</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.pdfbox</groupId>
                    <artifactId>pdfbox</artifactId>
                    <version>2.0.4</version>
                </dependency>
                <dependency>
                    <groupId>com.gd</groupId>
                    <artifactId>gd-security</artifactId>
                    <version>2.5</version>
                </dependency>
                <dependency>
                    <groupId>commons-beanutils</groupId>
                    <artifactId>commons-beanutils-core</artifactId>
                    <version>1.8.3</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.axis</groupId>
                    <artifactId>axis</artifactId>
                    <version>1.4</version>
                </dependency>
                <dependency>
                    <groupId>org.jsoup</groupId>
                    <artifactId>jsoup</artifactId>
                    <version>1.6.1</version>
                </dependency>
                <dependency>
                    <groupId>net.sf.json-lib</groupId>
                    <artifactId>json-lib</artifactId>
                    <version>2.4</version>
                    <classifier>jdk15</classifier>
                </dependency>
                <dependency>
                    <groupId>com.cndatacom</groupId>
                    <artifactId>commons-best</artifactId>
                    <version>1.0</version>
                </dependency>
                <dependency>
                    <groupId>com.sybase</groupId>
                    <artifactId>jconn3</artifactId>
                    <version>3-6.0</version>
                </dependency>
                <dependency>
                    <groupId>javax.xml</groupId>
                    <artifactId>jaxrpc</artifactId>
                    <version>1.1</version>
                </dependency>
                <dependency>
                    <groupId>org.bouncycastle</groupId>
                    <artifactId>bcprov-jdk15on</artifactId>
                    <version>1.52</version>
                </dependency>
                <dependency>
                    <groupId>javax.servlet</groupId>
                    <artifactId>javax.servlet-api</artifactId>
                    <version>3.0.1</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpmime</artifactId>
                    <version>4.3</version>
                </dependency>
                <dependency>
                    <groupId>commons-discovery</groupId>
                    <artifactId>commons-discovery</artifactId>
                    <version>0.5</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.cw</groupId>
                    <artifactId>kf.ats.gvnsvr.base</artifactId>
                    <version>${project.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.cw</groupId>
                    <artifactId>kf.ats.gvnsvr.common</artifactId>
                    <version>${project.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.cw</groupId>
                    <artifactId>kf.ats.gvnsvr.client</artifactId>
                    <version>${project.version}</version>
                </dependency>
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.client.ay</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.client.gddg</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.client.gdstb</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.client.gz</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.client.jd</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.client.jimo</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.client.jm</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.client.kaifeng</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.client.mzmx</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.client.nansha</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.client.qy</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.client.sc</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
                <dependency>
                    <groupId>com.kamfu.ats.cw</groupId>
                    <artifactId>kf.ats.gvnsvr.client.taizhou</artifactId>
                    <version>${project.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.cw</groupId>
                    <artifactId>kf.ats.gvnsvr.client.tzlq</artifactId>
                    <version>${project.version}</version>
                </dependency>            
                <dependency>
                    <groupId>com.kamfu.ats.cw</groupId>
                    <artifactId>kf.ats.gvnsvr.server</artifactId>
                    <version>${project.version}</version>
                </dependency>
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.server.ay</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.server.gddg</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.server.gdstb</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.server.gdxn</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.server.gz</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.server.gzlw</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.server.jd</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.server.jimo</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.server.kaifeng</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.server.jm</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.server.mzmx</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.server.nansha</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.server.qy</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.server.sc</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
                <dependency>
                    <groupId>com.kamfu.ats.cw</groupId>
                    <artifactId>kf.ats.gvnsvr.server.taizhou</artifactId>
                    <version>${project.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.cw</groupId>
                    <artifactId>kf.ats.gvnsvr.server.tzlq</artifactId>
                    <version>${project.version}</version>
                </dependency>                        
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.server.ui</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.server.ui.gdstb</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.visibledecrypttool</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--             </dependency> -->
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.gvnsvr.serverapp</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--                 <type>war</type> -->
    <!--             </dependency> -->
                <dependency>
                    <groupId>com.kamfu.ats.log</groupId>
                    <artifactId>kf.log.logencrypt</artifactId>
                    <version>${project.version}</version>
                </dependency>
    <!--             <dependency> -->
    <!--                 <groupId>com.kamfu.ats.cw</groupId> -->
    <!--                 <artifactId>kf.ats.plt.app.installdir</artifactId> -->
    <!--                 <version>${project.version}</version> -->
    <!--                 <type>pom</type> -->
    <!--             </dependency> -->
                <dependency>
                    <groupId>com.kamfu.ats.cw</groupId>
                    <artifactId>gvnsvr.axis2.stub</artifactId>
                    <version>${project.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.kamfu.ats.cw</groupId>
                    <artifactId>kf.ats.gvnsvr.supervisor.web</artifactId>
                    <version>${project.version}</version>
                    <type>war</type>
                </dependency>
                
                     <dependency>
                      <artifactId>hessian</artifactId>
                      <groupId>com.caucho</groupId>
                      <version>4.0.38</version>
                  </dependency>  
            </dependencies>
        </dependencyManagement>
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>3.0.0</version>
                        <configuration>
                            <descriptors>
                                <descriptor>src/assembly/bin.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <source>1.6</source>
                            <target>1.6</target>
                        </configuration>
                    </plugin>                
                      <plugin>
                          <groupId>org.apache.maven.plugins</groupId>
                          <artifactId>maven-source-plugin</artifactId>
                          <version>3.0.1</version>
                          <configuration>
                             <attach>true</attach>
                          </configuration>
                         <executions>
                             <execution>
                                 <phase>compile</phase>
                                     <goals>
                                        <goal>jar</goal>
                                     </goals>
                             </execution>
                        </executions>
                    </plugin>                
                </plugins>
            </pluginManagement>
        </build>
        <distributionManagement>
            <repository>
                <id>releases</id>
                <url>http://localhost:8081/nexus/content/repositories/releases/</url>
            </repository>
            <snapshotRepository>
                <id>snapshots</id>
                <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
            </snapshotRepository>
        </distributionManagement>
    </project>
    pom.xml

      2)子项目

    <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>
        <artifactId>kf.ats.gvnsvr.base</artifactId>
        <parent>
            <groupId>com.kamfu.ats.cw</groupId>
            <artifactId>cw-parent</artifactId>
            <version>20190807-RELEASE</version>
            <relativePath>../cw-parent</relativePath>
        </parent>
        <build>
            <sourceDirectory>src</sourceDirectory>
            <resources>
                <resource>
                    <directory>src</directory>
                    <excludes>
                        <exclude>**/*.java</exclude>
                    </excludes>
                </resource>
            </resources>
        </build>
        <dependencies>
    <!--         <dependency> -->
    <!--             <groupId>com.kamfu.ats55.platform</groupId> -->
    <!--             <artifactId>kf.ats.plt.server.compatible</artifactId> -->
    <!--         </dependency> -->
            <dependency>
                <groupId>com.kamfu.ats.cw</groupId>
                <artifactId>kf.ats.gvnsvr.common</artifactId>
            </dependency>
            <dependency>
                <groupId>com.kamfu.ats.sbglq</groupId>
                <artifactId>kf.ats.plt.client.base.extend</artifactId>
            </dependency>
            <dependency>
                <groupId>com.kamfu.ats.ggywpt</groupId>
                <artifactId>kf.ats.buss.front</artifactId>
            </dependency>
            <dependency>
                <groupId>com.kamfu.ats.ggywpt</groupId>
                <artifactId>kf.ats.buss.back</artifactId>
            </dependency>
            <dependency>
                <groupId>com.kamfu.ats.jcpt</groupId>
                <artifactId>kf.ats.plt.minisys.clientapp</artifactId>
            </dependency>
            <dependency>
                <groupId>com.kamfu.ats.ywzcxt</groupId>
                <artifactId>kf.ats.oam.client</artifactId>
            </dependency>
            <dependency>
                <groupId>com.kamfu.ats.ywzcxt</groupId>
                <artifactId>kf.ats.plt.supervisor.client</artifactId>
            </dependency>
        </dependencies>
    </project>
    pom.xml

    6.Maven本地项目之间的相互依赖

    被依赖项目

    当前项目

    7.maven的两种可运行jar打包方式。

      1、内置依赖,

    <plugins>
                <!-- 内置打包法 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <!-- 用这个maven打包插件 -->
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>2.3</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <!-- 默认值为true.注意这个属性,如果你用这个插件来deploy,或者发布到中央仓库,这个属性会缩减你的pom文件,会把你依赖的<dependency>干掉 -->
                                <createDependencyReducedPom>false</createDependencyReducedPom>
                                <transformers>
                                    <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                        <resource>META-INF/spring.handlers</resource>
                                    </transformer>
                                    <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                        <resource>META-INF/spring.schemas</resource>
                                    </transformer>
                                    <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                        <!-- 这个是你的程序入口文件 -->
                                        <mainClass>com.alibaba.dubbo.container.Main</mainClass>
                                    </transformer>
                                </transformers>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <!-- 设置字符编码集 -->
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
            </plugins>
    View Code

      2、外部依赖。

    <plugins>
                <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <classesDirectory>target/classes/</classesDirectory>
                        <archive>
                            <manifest>
                                <mainClass>com.alibaba.dubbo.container.Main</mainClass>
                                <!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
                                <useUniqueVersions>false</useUniqueVersions>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>lib/</classpathPrefix>
                            </manifest>
                            <manifestEntries>
                                <Class-Path>.</Class-Path>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <type>jar</type>
                                <includeTypes>jar</includeTypes>
                                <useUniqueVersions>false</useUniqueVersions>
                                <outputDirectory>
                                    ${project.build.directory}/lib
                                </outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
    View Code

    8.maven上传源码到私服  

                      <plugin>
                          <groupId>org.apache.maven.plugins</groupId>
                          <artifactId>maven-source-plugin</artifactId>
                          <version>3.0.1</version>
                          <configuration>
                             <attach>true</attach>
                          </configuration>
                         <executions>
                             <execution>
                                 <phase>compile</phase>
                                     <goals>
                                        <goal>jar</goal>
                                     </goals>
                             </execution>
                        </executions>
                    </plugin> 
    pom.xml

     

  • 相关阅读:
    Spring 中的重试机制,简单、实用!
    Docker 常用命令,还有谁不会?
    Java 对象不使用时为什么要赋值为 null?
    为什么 Nginx 比 Apache 更牛叉?
    你还在用命令看日志?快用 Kibana 吧,一张图片胜过千万行日志!
    golang如何体现面向对象思想
    golang 三⾊标记+GC混合写屏障机制
    Golang中逃逸现象-变量何时 栈何时堆
    golang调度器原理与GMP模型设计思想
    golang 程序内存分析方法
  • 原文地址:https://www.cnblogs.com/liandy001/p/11287278.html
Copyright © 2020-2023  润新知