nexus本地maven仓库部署及下载

2 篇文章 0 订阅
1 篇文章 0 订阅

部署环境:
系统版本:Mac os 12.0.1
Nexus版本:3.37.3

1.下载Nexus安装包下载地址

在这里插入图片描述
跟据自己的设备下载合适的安装包版本
Unix archive:linux
Windows archive:windows
OSX archive:mac os

2.启动Nexus

找到安装包路径
你的文件目录/nexus-3.37.3-02/bin
在这里插入图片描述
打开cmd进入到安装包下的bin目录启动你的nexus
在这里插入图片描述
看到如下字样,则表启动成功
在这里插入图片描述

3.访问Nexus

不知道你的nexus访问地址?没关系,我教你。
你的文件目录/nexus-3.37.3-02/etc/nexus-default.properties
在这里是你的nexus配置文件
在这里插入图片描述
打开配置文件
在这里插入图片描述
application-port=访问Nexus端口号(默认8081)
application-host=访问Nexus的ip地址(默认localhost本地ip)
所以你的访问路径就是 http://localhost:8081

看到如下图则表示启动成功
在这里插入图片描述

4.登录Nexus

在这里插入图片描述
到这里肯定有人会问,我不知道账号密码,怎么办。
很多文章会告诉你,账号是admin,密码是admin123
但是,那是旧版本的Nexus,账号依然是admin,新版本的密码可不是,别瞎说。

你的文件目录/nexus-3.37.3-02/etc/sonatype-work/nexus3/admin.password
提示:我这里已经修改过了密码,所以admin.password就消失了
在这里插入图片描述
打开文件,直接复制密码登录即可,登录成功之后会让你再输入一次密码,这是修改密码的步骤,以后将用这个密码登录Nexus。

5.打包Jar上传到Nexus
1)全局配置Nexus

在这里插入图片描述
找到maven安装目录
文件路径/maven/版本号/libexec/conf/settings.xml
在这里插入图片描述

2)servers节点

在这里插入图片描述

<server><!-- 发布版本-->
             <id>nexus</id> <!-- 随意填写,但项目中repository的id得与这里一致-->
              <username>admin</username> <!-- 账户-->
           <password>admin123</password>  <!-- 密码-->
        </server>
        <server><!-- 发布版本-->
      	   <id>nexus-releases</id> <!-- 随意填写,但项目中repository的id得与这里一致-->
       	   <username>admin</username> <!-- 账户-->
           <password>admin123</password>  <!-- 密码-->
        </server>
        <server><!-- 发布版本-->
             <id>nexus-snapshots</id> <!-- 随意填写,但项目中repository的id得与这里一致-->
              <username>admin</username> <!-- 账户-->
           <password>admin123</password>  <!-- 密码-->
        </server>
3)mirrors节点

在这里插入图片描述

<mirror>
      <id>nexus</id>
      <!--表示访问哪些工厂时需要使用镜像-->
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/repository/maven-public/</url>
    </mirror>
6.打包上传Jar

这里以vscode为例子,其他开发工具大同小异

1)pom.xml配置你的Nexus仓库地址信息

在这里插入图片描述

<!-- 本地nexus私有库-->
  <distributionManagement>
    <snapshotRepository>
      <id>nexus-snapshots</id>
      <url>http://localhost:80801/repository/maven-snapshots/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </snapshotRepository>
    <repository>
      <id>nexus-releases</id>
      <url>http://localhost:80801/repository/maven-releases/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </distributionManagement>

2)在终端cmd输入mvn clean

在这里插入图片描述

3)在终端cmd输入mvn deploy

在这里插入图片描述
看到BUILD SUCCESS字样则代表上传成功。

回到Nexus查看上传的jar
在这里插入图片描述在这里插入图片描述
在这里即可以看到刚才上传的jar文件(别纠结我的为什么那么多个,因为我之前就上传了好几个)

7.引用Nexus库jar

找到maven安装目录
文件路径/maven/版本号/libexec/conf/settings.xml

1)profiles节点

在这里插入图片描述

<profile>
            <!--profile 的 id-->
            <id>nexus</id>
            <repositories>
                <repository>
                    <!--仓库 id,repositories 可以配置多个仓库,保证 id 不重复-->
                    <id>nexus</id>
                    <!--仓库地址,即 nexus 仓库组的地址-->
                    <url>http://localhost:8081/repository/maven-public/</url>
                    <!--是否下载 releases 构件-->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <!--是否下载 snapshots 构件-->
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <!-- 插件仓库,maven 的运行依赖插件,也需要从私服下载插件 -->
                <pluginRepository>
                    <!-- 插件仓库的 id 不允许重复,如果重复后边配置会覆盖前边 -->
                    <id>public</id>
                    <name>Public Repositories</name>
                    <url>http://localhost:8081/repository/maven-public/</url>
                    <!--是否下载 releases 构件-->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <!--是否下载 snapshots 构件-->
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
2)activeProfiles节点

激活配置在这里插入图片描述

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

到这里,你的项目已经可以正常使用Nexus了。

end

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值