nexus了解和使用

nexus是一个强大的maven仓库管理工具,使用nexus可以方便的管理内部仓库,也就是私服,专门用于管理公司内部的jar包,可以将公司内部的jar包上传到nexus中。

一、下载和安装启动

去nexus官网:https://www.sonatype.com/ ,下载然后进行解压即可,官网下载比较慢,也有可能无法进行下载,如果无法下载,解决方案参加博客: https://blog.csdn.net/weixin_44765605/article/details/103020547
下载成功后解压出现如下图两个文件夹:上面一个是nexus安装目录,work是一个工作目录。

cmd进入nexus安装目录下的bin目录,执行nexus.exe/run命令启动nexus服务。启动成功在浏览器输入localhost:8081即可出现nexus页面。进入如下界面:

可以进行登录,初始用户名:admin,刚开始下载登录时的密码在work目录中,但是一般会设置成admin123。

如上图可以对仓库repository进行管理操作,例如查看仓库详情,新建一个仓库等。name是仓库名称,type是仓库类型,仓库类型解释如下:

二、上传和下载jar包

1、上传jar到nexus中。只需要配置两个地方即可。
在maven的conf/settings.xml文件中的如下节点中配置如下内容:

<servers>
    <!-- conf private maven repository in there,server可以配置多个-->
    <server>
        <id>releases</id>
        <!-- nexus登录的用户名和密码-->       
        <username>admin</username>
        <password>admin123</password>
    </server>

</servers>

此外需要在要上传jar的项目的pom.xml文件中,配置上传路径:

<!--nesxus上传jar到私服-->
<distributionManagement>
    <repository>
        <!--这个id需要和上面settings.xml中配置的id一致--> 
        <id>releases</id>   
        <url>http://localhost:8081/repository/testnesxus/</url>
    </repository>
</distributionManagement>

配置完成之后可以直接点击deploy按钮,或者cmd进入项目目录中执行mvn deploy命令就可以将jar上传到私服中了。
但有时会上传失败,如果上传失败了可参考以下解决方案:

  • 创建的仓库类型一定要是hosted类型的,否则无法上传。
  • Snapshot库发布的版本必须以SNAPSHOT结尾。
  • release发布的版本不能以SNAPSHOT结尾。

参考博客: https://blog.csdn.net/qq_32971807/article/details/79006273
nexus界面上传jar包和删除jar包可参见博客: https://blog.csdn.net/u011051912/article/details/105634265

2、从nexus中下载jar包
从nexus中下载jar只需要配置maven的settings配置文件即可,依赖可以直接在项目pom中引入坐标即可。
在settings配置文件中的如下节点中配置如下内容即可:

<profiles>
    <!--可以配置多个profile -->
    <profile>
        <id>helloworld</id>
        <!--远程仓库列表-->
        <repositories>
            <repository>
                <id>down1</id>
                <url>http://localhost:8081/repository/testnesxus/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </repository>
        </repositories>

    </profile>

</profiles>

其他nexus相关博客:
(1) https://blog.csdn.net/qh870754310/article/details/83780812 (nexus介绍)
(2) https://blog.csdn.net/qq_33188563/article/details/82154118 (nexus私服)
(3) https://blog.csdn.net/lk142500/article/details/95869196?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase (使用nexus创建私服)

猜你喜欢

转载自www.cnblogs.com/jasonboren/p/12945044.html