Java Web 学习笔记(三) 利用 Nexus 搭建 Maven 本地私服

Nexus介绍

Nexus是一个Maven仓库管理器,用来搭建私有仓库服务器。建立公司/组织的私有仓库的的好处是便于管理,节省公网带宽,利用内网下载依赖项速度快,还有一个非常有用的功能就是能有效管理内部项目的SNAPSHOT版本,实现各个模块间的共享.

下载及安装Nexus

下载Nexus

下载地址:https://www.sonatype.com/download-oss-sonatype

下载 Nexus

笔者下载的是Nexus OSS,即社区版,版本 3.2.0

安装Nexus

Nexus的安装很简单,下载后直接解压到系统盘根目录即可,可以看到解压出的文件中一共包含两个目录:

  • nexus-3.2.0-01:这是Nexus的程序目录。

  • sonatype-work:这个相当于Nexus的数据目录。

启动Nexus

Nexus的安装目录中有启动程序,位于Nexus安装目录bin目录下,但是不能直接双击运行,需要通过命令行启动。

启动命令行,首先 cd 到 Nexus的安装目录 bin 目录下,输入 nexus /run 即可启动Nexus,Nexus启动过程中会自我部署站点,这个过程可能比较慢,当然也可以安装成windows服务(n exus /install ),随系统一起启动。

启动 Nexus

默认端口是 8081,在浏览器中输入:http://localhost:8081/ 即可打开 Nexus 管理界面。
可以登录Nexus系统,默认管理员的 用户名是: admin , 密码是:admin123 。
登录成功后界面如下:

Nexus 主界面

Nexus安装完成后就已经包含了 Maven 的仓库,涉及到的仓库有:

  • maven-central: Maven 中央代理库

  • maven-releases: 本地发布的版本库,初始是空的

  • maven-snapshots: 一个快照库,可以存放项目开发各个阶段的快照

其中 maven-central 是代理库,而 maven-releases 和 maven-snapshots 是 类型为 hosted 库,用于发布自己的项目。
另外还有一个 maven-public 库,这实际上是以上三个库的组合,类型为 group。

配置Nexus

通过Web界面可以对Nexus服务器进行各种配置管理,这里我只介绍一下如何配置 Maven 代理库。

Maven 中央代理库配置

登录Nexus管理界面,点击 Server administration and configuration 按钮 进入管理界面,在左边选择 respositories

Nexus 管理界面

选择 maven-central 进入 Maven 中央代理库的配置界面,在 Proxy 中 配置远程Maven中央库的地址,可以看到默认配置的是 Maven 官方的中央库,我们把他修改成阿里云上的代理库,即:http://maven.aliyun.com/nexus/content/groups/public/

配置远程中央代理库

Maven配置

下面配置一下本机的Maven环境,让它连接刚刚创建的 Nexus 私服。

打开 Maven 安装目录 conf 目录下 Settings.xml,在 servers 节点下配置Nexus服务器的连接信息,如下:

配置 Servers

<server>
      <id>nexus</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>nexus-releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>nexus-snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>

然后在 mirrors 节点添加镜像,如下:

配置 Mirrors

<mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://192.168.6.59:8081/repository/maven-public/</url>
    </mirror>

此外再配置一下 profile 信息,如下:

配置 Profile

<profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>http://192.168.6.59:8081/repository/maven-public/</url>
          <release>
            <enabled>true</enabled>
          </release>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
            <id>central></id>
            <url>http://192.168.6.59:8081/repository/maven-public/</url>
            <release>
                <enabled>true</enabled>
            </release>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>

最后指定 activeProfile,如下:

配置 activeProfile

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

至此,配置完成!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值