美文网首页
搭建maven私有仓库

搭建maven私有仓库

作者: xhh199090 | 来源:发表于2018-07-27 09:49 被阅读0次

    下载并解压nexus2.x

    [root@zdh-10 warehouse]# pwd
    /home/warehouse
    [root@zdh-10 warehouse]# tar zxvf nexus-2.14.3-02-bundle.tar.gz
    [root@zdh-10 warehouse]# cd nexus-2.14.3-02
    [root@zdh-10 nexus-2.14.3-02]# cd bin/jsw/conf/
    [root@zdh-10 conf]# vi wrapper.conf
    wrapper.java.command=/home/jdk1.7.0_80/bin/java
    [root@zdh-10 conf]# cd ../../..
    [root@zdh-10 nexus-2.14.3-02]# cd conf/
    [root@zdh-10 conf]# pwd
    /home/warehouse/nexus-2.14.3-02/conf
    [root@zdh-10 conf]# vi nexus.properties
    application-port=8082 //方便以后装nexus3.x
    nexus-work=${bundleBasedir}/sonatype-work/nexus
    [root@zdh-10 nexus-2.14.3-02]# pwd
    /home/warehouse/nexus-2.14.3-02
    [root@zdh-10 nexus-2.14.3-02]# cp bin/nexus /etc/init.d/nexus2
    [root@zdh-10 nexus-2.14.3-02]# vi /etc/init.d/nexus2
    NEXUS_HOME="/home/warehouse/nexus-2.14.3-02"
    RUN_AS_USER=root
    [root@zdh-10 nexus-2.14.3-02]# chkconfig --add nexus2
    [root@zdh-10 nexus-2.14.3-02]# chkconfig nexus2 on
    启动命令
    [root@zdh-10 nexus-2.14.3-02]# /etc/init.d/nexus2 start


    WARNING - NOT RECOMMENDED TO RUN AS ROOT


    Starting Nexus OSS...
    Started Nexus OSS.

    停止服务
    [root@zdh-10 nexus-2.14.3-02]# /etc/init.d/nexus2 stop


    ARNING - NOT RECOMMENDED TO RUN AS ROOT


    Stopping Nexus OSS...
    Nexus OSS was not running.
    在浏览器输入http://10.43.159.10:8082/nexus,登录名/密码默认是admin/admin123

    图片1.png

    新建一个私有仓库,点击Add-->Proxy
    输入ID和Name,选择Allow Redeploy,将Heath Check设置为false,保存
    选择Public Repositories,将proxy类型的移到Ordered Group Repositories中


    图片3.png

    我们会发现Browse Index和Browse Storage为空,操作以下步骤:
    右击Public Repositories,选择Repair Index


    图片4.png

    下载Index会非常慢,可以手动配置
    <u>http://repo.maven.apache.org/maven2/.index/</u>
    拖到最下面,下载
    <u>nexus-maven-repository-index.gz</u>
    <u>nexus-maven-repository-index.properties</u>
    indexer-cli-5.1.1.jar
    上传三个文件到/home/warehouse/nexus-2.14.3-02/sonatype-work/nexus/indexer/ZTE-Central-ctx/
    [root@zdh-10 ZTE-Central-ctx]# java -jar indexer-cli-5.1.1.jar -u nexus-maven-repository-index.gz -d ./
    Index Folder: /home/warehouse/nexus-2.14.3-02/sonatype-work/nexus/indexer/ZTE-Central-ctx
    Output Folder: /home/warehouse/nexus-2.14.3-02/sonatype-work/nexus/indexer/ZTE-Central-ctx
    Total time: 5 min 22 sec
    Final memory: 111M/265M
    之后重启nexus

    [root@zdh-10 ZTE-Central-ctx]# /etc/init.d/nexus2 restart
    登录页面http://10.43.159.10:8082/nexus,就可以看到Browse Index有内容了

    图片5.png

    至此,nexus基本可以用了,但是本地私服中Storage还是空的,通过下面配置可以填充本地Storage
    在私服安装maven并配置环境变量,在$MAVEN_HOME/conf中,修改settings.xml
    settings.xml文件中增加profile
    <profile>
    <id>nexusProfile</id>
    <repositories>
    <repository>
    <id>nexus</id>
    <name>Nexus Repository</name>
    <url>http://10.43.159.10:8082/nexus/content/groups/public/</url>
    <releases>
    <enabled>true</enabled>
    </releases>
    <snapshots>
    <enabled>true</enabled>
    </snapshots>
    </repository>
    </repositories>
    </profile>


    <activeProfiles>
    <activeProfile>nexusProfile</activeProfile>
    </activeProfiles>
    增加mirror
    <mirror>
    <id>public</id>
    <mirrorOf>central</mirrorOf>
    <name>Repository</name>
    <url>http://10.43.159.10:8082/nexus/content/groups/public/</url>
    </mirror>
    <mirror>
    <id>proxy.repository</id>
    <mirrorOf>*,!central</mirrorOf>
    <name>Proxy Repository</name>
    <url>http://10.43.159.10:8082/nexus/content/groups/public/</url>
    </mirror>
    随便到一个maven项目下执行编译,会自动下载相关的jar并保存一份到本地仓库
    之前本地仓库为空,编译完刚刚的maven项目,使用到的相关包已经在本地仓库自动保存了一份

    图片7.png

    登录页面http://10.43.159.10:8082/nexus,就可以看到Browse Storage有内容了

    图片8.png

    相关文章

      网友评论

          本文标题:搭建maven私有仓库

          本文链接:https://www.haomeiwen.com/subject/purwmftx.html