zoukankan      html  css  js  c++  java
  • 配置 Maven 项目使用 Nexus 仓库

    第一种方法:

    去maven 项目 helo-world 项目 配置pom.xml,在pom.xml配置 只有本项目才用到这个Nexus仓库

    [root@ci-node2 ~]# cd /root/hello-world
    [root@ci-node2 hello-world]# ll
    total 4
    -rw-r--r-- 1 root root 1683 Aug 26  2010 pom.xml
    drwxr-xr-x 4 root root   30 Oct 10  2009 src
    drwxr-xr-x 7 root root  188 Apr 22 01:12 target

    第二种方法

    在maven配置文件配置,配置完所有项目都去Nexus仓库去拉,把Nexus作为中央仓库来处理,全局更好

    在 maven 的 setting.xml 文件中配置私服配置,这种方式配置后所有本地使用该配置的
    maven 项目的 pom 文件都无需配置私服下载相关配置

    maven配置文件 setting.xml 在/usr/local/maven/conf

    [root@ci-node2 hello-world]# cd /usr/local/maven/conf/
    [root@ci-node2 conf]# ll
    total 16
    drwxr-xr-x 2 root root    37 Nov 11  2015 logging
    -rw-r--r-- 1 root root 10216 Nov 11  2015 settings.xml
    -rw-r--r-- 1 root root  3649 Nov 11  2015 toolchains.xml
    [root@ci-node2 conf]# vim settings.xml 

    在<profiles></profiles>之间加入下面的配置  

    分别配置 profile id(配置的标识),配置仓库 nexus

    url 配置是

    点击

     

    点击maven-public

     url配置 http://192.168.31.13:8081/repository/maven-public/ 地址

     插件地址也是 http://192.168.31.13:8081/repository/maven-public/

    <profile>

        <id>my-nexus</id>

    <repositories>

    <!-- 私有库地址-->

        <repository>

            <id>nexus</id>

            <name>nexus</name>

            <url>http://192.168.31.13:8081/repository/maven-public/</url>

            <snapshots>

                <enabled>true</enabled>

            </snapshots>

            <releases>

                <enabled>true</enabled>

            </releases>

        </repository>

    </repositories>

    <pluginRepositories>

    <!--插件库地址-->

            <pluginRepository>

                <id>nexus</id>

                <url>http://192.168.31.13:8081/repository/maven-public/</url>

                <releases>

                    <enabled>true</enabled>

                </releases>

                <snapshots>

                    <enabled>true</enabled>

                </snapshots>

             </pluginRepository>

    </pluginRepositories> 
    </profile>

     添加了一组profile配置,配置了私有仓库和插件地址

    现在要启动上面的配置:

    在<settings></settings>之间加入下面的配置,激活使用上面的配置

    启动上面的my-nexus配置  加上文件id

    <activeProfiles>

        <activeProfile>my-neuxs</activeProfile>

    </activeProfiles>

    注:profile 名字要对应

    在<mirros></mirros>之间加入如下配置

    加了id

    url地址也是  http://192.168.31.13:8081/repository/maven-public/

    <mirror>

        <id>nexus-myself</id>

        <!--*指的是访问任何仓库都使用我们的私服-->

        <mirrorOf>*</mirrorOf>

        <name>Nexus myself</name>

        <url>http://192.168.31.13:8081/repository/maven-public/</url>

    </mirror>

    这段配置意思是只要访问中心仓库的东西,都去私服去访问,私服没有,再去中心仓库下载

    然后wq保存 配置

    配置完成后, 回到去maven 项目 helo-world 项目  

    [root@ci-node2 ~]# cd /root/hello-world
    [root@ci-node2 hello-world]# ll
    total 4
    -rw-r--r-- 1 root root 1683 Aug 26  2010 pom.xml
    drwxr-xr-x 4 root root   30 Oct 10  2009 src
    drwxr-xr-x 7 root root  188 Apr 22 01:12 target

    执行前先把.m2仓库删除,因为默认已经下载到.m2仓库,执行命令默认会找m2仓库,如果m2仓库有,就不去私服下载

    [root@ci-node2 hello-world]# rm -rf /root/.m2/

    执行 mvn clear 把上次构建清掉

    地址改变了,前面下载都是在maven中央仓库下载,现在变成我们私服地址

     私服没有,会去中央仓库下载,先下载到我们的私服,现在m2仓库也有了

    当我们再次执行 mvn 命令时,下载构件的地址变为我们的私服地

    现在仓库地址也有

     现在 maven-public 库有东西了

    我们再执行 mvn package

    他会把更多的下载到我们本地,先下载到私服Nexus仓库里面,再下载到m2仓库

    我们的私服也缓存了相应的构件在本地

  • 相关阅读:
    【POJ3069】Saruman's Army
    【POJ2453】An Easy Problem
    【POJ2386】Lake Counting
    【POJ2251】Dungeon Master
    【POJ1664】放苹果
    【基础】枚举学习笔记
    算法时空复杂度【OI缩水版】
    【POJ2018】Best Cow Fences
    【POJ3889】Fractal Streets(分形图)
    【BZOJ2296】随机种子(构造)
  • 原文地址:https://www.cnblogs.com/mingerlcm/p/12764713.html
Copyright © 2011-2022 走看看