使用nexus搭建maven私服

本文介绍如何使用Nexus搭建Maven私服,包括安装启动、配置仓库、增加镜像及项目配置等步骤,有效提高局域网内的Maven依赖下载速度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用nexus搭建maven私服

国内访问maven仓库速度渣渣,公司访问外网速度不快,即使用阿里云镜像效果也不佳。在局域网内搭建Maven私服,除了能从私服加速下载jar包,还能将内部通用模块发布在私服上供其他同事使用。对内部项目部署很有帮助。

安装和启动nexus

下载nexus-2.14.2-01-bundle.tar.gz
https://www.sonatype.com/download-oss-sonatype

# 添加用户
adduser nexus  
passwd nexus   
su nexus

cd /home
mkdir nexus
cd nexus
tar xvzf nexus-2.14.2-01-bundle.tar.gz
cd nexus-2.14.2-01/bin

#启动nexus
./nexus start

浏览器中输入http://127.0.0.1:8081/nexus/

nexus的maven仓库配置

开启远程索引

新搭建的neuxs环境只是一个空的仓库,需要手动和远程中心库进行同步,nexus默认是关闭远程索引下载,最重要的一件事情就是开启远程索引下载。登陆nexus系统,默认用户名密码为admin/admin123

  • 点击左边Administration菜单下面的Repositories,找到右边仓库列表中的Apache Snapshots,Central,然后在configuration下把Download Remote Indexes修改为true
    这里写图片描述
  • 仓库上分别右键,选择Repari Index,这样Nexus就会去下载远程的索引文件。
    这里写图片描述

这样设置以后, Nexus会自动从远程中央仓库下载索引文件, 为了检验索引文件自动下载是否生效,可以却换到Browse Index查看

增加阿里云镜像

Repositories –> Add –>ProxyRepository
阿里的maven镜像:
http://maven.aliyun.com/nexus/content/groups/public/
Checksum Policy 可以改为ignore

这里写图片描述
Repositories –> Public Repositories
将右侧栏全部加入左侧栏即可
这里写图片描述

项目maven配置

maven的全局配置文件

修改maven的settings.xml配置文件,如C:\Users\xieyue.m2\settings.xml

    <!--deploy发布项目到私服的用户密码-->
    <servers>
        <server>  
          <id>releases</id>  
          <username>deployment</username>  
          <password>xxx</password>  
        </server>  
        <server>  
          <id>snapshots</id>  
          <username>deployment</username>  
          <password>xxx</password>  
        </server>  
    </servers>

    <!--使用私服仓库-->
    <profiles>
        <profile>
            <repositories>  
                <repository>  
                    <id>nexus</id>  
                    <name>nexus</name>  
                    <url>http://132.97.8.177:8081/nexus/content/groups/public/</url>  
                    <releases>  
                        <enabled>true</enabled>  
                    </releases>  
                    <snapshots>  
                        <enabled>true</enabled>  
                    </snapshots>  
                </repository>  
            </repositories>  
        </profile>
     </profiles>

    <activeProfiles>
      <activeProfile>nexus</activeProfile>
    </activeProfiles>

项目的POM.xml设置

        <!-- mvn deploy的发布地址 -->
    <distributionManagement>
        <repository>
            <id>releases</id>
            <name>Internal Releases</name>
            <url>http://132.97.8.177:8081/nexus/content/repositories/releases</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Internal Snapshots</name>
            <url>http://132.97.8.177:8081/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>


    <!-- 使用本地maven私库 -->
    <repositories>  
        <repository>  
            <id>nexus</id>  
            <name>nexus</name>  
            <url>http://132.97.8.177:8081/nexus/content/groups/public/</url>  
            <releases>  
                <enabled>true</enabled>  
            </releases>  
            <snapshots>  
                <enabled>true</enabled>  
            </snapshots>  
        </repository>  
    </repositories> 

参考资料

http://books.sonatype.com/nexus-book/reference/installing.html
http://blog.csdn.net/ClementAD/article/details/52670968
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值