• Maven私服搭建与使用:nexus,repository,mirror,distributionManagement


    一、应用场景与相关介绍

    • 私服public仓库理解:私服,即私人的服务器,可以看作就是一台电脑。这个电脑专门供我们连接然后下载和存放jar包,而我们给这个电脑分为了几个仓库,其中一个叫做public。不同仓库存放不同类型的jar包。
    • 第三方jar包下载:让私服public仓库可以代替中央仓库 central,成为类似于阿里云镜像一样的仓库。
      • mirro实现:在settings.xml 中的 将私服的public仓库设置为 中央仓库central 的镜像。
        • 为什么这样就能成为类似于阿里云镜像一样的仓库呢?因为我们连接到私服仓库下载jar包,如果仓库没有,它会到我们指定的地址去下载。以后我们再去下载就可以直接从仓库拿到了。 如果还找不到,就会去settings.xml或者pom.xml中配置的下一个仓库查找。
      • repository实现:在 中添加私服的public仓库为远程仓库。
        • settings.xml 中的 -
        • pom.xml 中的 -
        • pom.xml 中的
    • 部署公司内部的jar包,对公司内部人员开放使用
      • 部署:设置部署公司内部releases版本jar包和 snapshot版本jar包的地址
      • 下载::将私服中releases和 snapshot仓库的地址添加进来。
        • 标签理解,当第一个repository找不到想要的jar包,就会去下一个repository中找。
    • 作用:服务器部署在公司局域网,下载速度快。可以部署公司内部的jar包供公司其他员工使用,同时保证安全性。

    二、下载安装

    2.1 下载

    Nexus下载

    2.2 解压

    • 解压
    [root@mysql-tomcat nexus]# ll
    total 211404
    -rw-r--r-- 1 root root 216470874 Sep  4 12:15 nexus-3.41.1-01-unix.tar.gz
    drwxr-xr-x 3 root root      4096 Sep  4 12:14 sonatype-work
    [root@mysql-tomcat nexus]# tar -zxvf nexus-3.41.1-01-unix.tar.gz
    ......
    [root@mysql-tomcat nexus]# ll
    total 211408
    drwxr-xr-x 10 root root      4096 Sep  4 12:16 nexus-3.41.1-01
    -rw-r--r--  1 root root 216470874 Sep  4 12:15 nexus-3.41.1-01-unix.tar.gz
    drwxr-xr-x  3 root root      4096 Sep  4 12:14 sonatype-work
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 删除压缩包
    [root@mysql-tomcat nexus]# rm -rf nexus-3.41.1-01-unix.tar.gz 
    [root@mysql-tomcat nexus]# ll
    total 8
    drwxr-xr-x 10 root root 4096 Sep  4 12:16 nexus-3.41.1-01
    drwxr-xr-x  3 root root 4096 Sep  4 12:14 sonatype-work
    [root@mysql-tomcat nexus]# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    三、Nexus配置

    3.1 启动服务

    在这里插入图片描述

    [root@mysql-tomcat nexus]# ll
    total 8
    drwxr-xr-x 10 root root 4096 Sep  4 12:16 nexus-3.41.1-01
    drwxr-xr-x  3 root root 4096 Sep  4 12:14 sonatype-work
    [root@mysql-tomcat nexus]# cd nexus-3.41.1-01/
    [root@mysql-tomcat nexus-3.41.1-01]# ll
    total 96
    drwxr-xr-x  3 root root  4096 Sep  4 12:16 bin
    drwxr-xr-x  2 root root  4096 Sep  4 12:16 deploy
    drwxr-xr-x  7 root root  4096 Sep  4 12:16 etc
    drwxr-xr-x  5 root root  4096 Sep  4 12:16 lib
    -rw-r--r--  1 root root   651 Aug 18 21:55 NOTICE.txt
    -rw-r--r--  1 root root 17321 Aug 18 21:55 OSS-LICENSE.txt
    -rw-r--r--  1 root root 41954 Aug 18 21:55 PRO-LICENSE.txt
    drwxr-xr-x  2 root root  4096 Sep  4 12:16 public
    drwxr-xr-x  3 root root  4096 Sep  4 12:16 replicator
    drwxr-xr-x 22 root root  4096 Sep  4 12:16 system
    [root@mysql-tomcat nexus-3.41.1-01]# cd bin
    [root@mysql-tomcat bin]# ll
    total 32
    drwxr-xr-x 2 root root  4096 Sep  4 12:16 contrib
    -rwxr-xr-x 1 root root 18620 Aug 18 21:55 nexus
    -rw-r--r-- 1 root root    15 Aug 18 21:55 nexus.rc
    -rw-r--r-- 1 root root  1635 Aug 18 21:55 nexus.vmoptions
    [root@mysql-tomcat bin]# ./ nexus start
    -bash: ./: Is a directory
    [root@mysql-tomcat bin]# ./nexus start
    WARNING: ************************************************************
    WARNING: Detected execution as "root" user.  This is NOT recommended!
    WARNING: ************************************************************
    Starting nexus
    [root@mysql-tomcat bin]# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    3.2 配置nexus

    3.2.1 登录

    点击登录

    在这里插入图片描述

    查看用户名和密码

    在这里插入图片描述

    在这里插入图片描述

    点击登录

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    3.2.2 配置

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    四、Nexus仓库使用

    章节概述

    • 创建新项目:MavenTest-Nexus

    • 使用新的本地仓库:maven_repository_nexus

    • 4.1 使用public仓库下载第三方jar包

      1. 刷新maven
    • 4.2 将开发的jar包部署到snapshot仓库

      1. 在新工程MavenTest-Nexus中创建类Demo
      2. 将MavenTest-Nexus工程的jar包部署到Nexus
    • 4.3 使用snapshot仓库下载内部的jar包

      1. 在任意工程中引入MavenTest-Nexus工程依赖

      2. 使用MavenTest-Nexus工程中的类Demo

    4.1 使用public仓库下载第三方jar包

    4.1.1 配置settings.xml

    在这里插入图片描述

      <servers>
    	<server>
          <id>nexus-mindid>
          <username>adminusername>
          <password>123456password>
        server>
      servers>
    
      <mirrors>
    	<mirror>
    		<id>nexus-mindid>
    		<mirrorOf>centralmirrorOf>
    		<name>Nexus publicname>
    		<url>http://120.77.44.184:8081/repository/maven-public/url>
    	mirror>
    
      mirrors>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    4.1.2 在IDEA中对Maven进行配置

    在这里插入图片描述

    4.1.3 刷新前本地仓库和Nexus public仓库

    • 本地仓库
      在这里插入图片描述
    • Nexus public仓库
      在这里插入图片描述

    4.1.4 刷新后本地仓库和Nexus public仓库

    在这里插入图片描述

    • 本地仓库

    在这里插入图片描述

    • Nexus public仓库

    在这里插入图片描述

    4.2 将开发的jar包部署到snapshot仓库

    4.2.1 创建类Demo

    在这里插入图片描述

    4.2.2 部署到Nexus

    • 配置pom.xml

    在这里插入图片描述

    • 部署

    部署前snapshots仓库

    在这里插入图片描述

    部署后snapshots仓库

    在这里插入图片描述
    在这里插入图片描述

    在这里插入图片描述

    4.3 使用snapshot仓库下载内部的jar包

    4.3.1 在另一个工程中引入MavenTest-Nexus工程的jar包

    在这里插入图片描述

    4.3.2 配置pom.xml

    在这里插入图片描述

    4.3.3 使用MavenTest-Nexus工程的jar包

    在这里插入图片描述

  • 相关阅读:
    Ant-design-vue Table 列表 columns 将作为导出功能入参
    简易租赁合同(免费)
    gin 中间件
    【MySQL】索引和事物
    Docker快速搭建漏洞靶场指南
    Java注解及自定义注解
    如何在 Apache Tomcat 中实现 SSL?
    STM32(五):STM32指南者-按键控制灯开关实验
    一招打通数据共享,软件开发框架让通信行业数字化转型更轻松
    信奥中的数学:进位制
  • 原文地址:https://blog.csdn.net/weixin_43401592/article/details/126687466