linux将本地库JAR批量导入到Nexus3.x

本文档详细介绍了如何在Linux环境中将本地JAR库批量导入到Nexus3.x私服,包括Nexus的搭建、创建本地仓库、编写shell脚本进行批量上传,并给出了遇到问题的解决方案,确保开发环境离线状态下仍能正常工作。
摘要由CSDN通过智能技术生成

linux将本地库JAR批量导入到Nexus3.x

1、问题描述

(1)由于公司的研发环境迁移到N网的不能联网,不过本地仓库已经有很多的 mavenjar 包了,便想将其从本地仓库导入到N网 Nexus 私服中。

(2)Nexus2.x 批量导入本地库是十分容易的,只需将库文件夹复制到对应 nexus 库下面,去网页刷新一下索引就OK了。在 Nexus3.x 中,我们可以很方便的使用 shell 脚本进行批量导入jar包。

2、搭建Nexus私服

2.1、官网下载:

地址:https://help.sonatype.com/repomanager3/product-information/download

2.2、上传并解压

tar -zxvf nexus-3.25.1-04-unix.tar.gz

2.3、修改默认端口

部署环境上一般要求五位端口号,这里把默认端口(8081)改为28081

# 进入etc文件夹
cd  /opt/nexus-3.25.1-04/etc
# 修改配置
vi nexus-default.properties
# 更改端口号 port
application-port=28081

2.4、修改内存分配:

# 进入bin目录
cd /opt/nexus-3.25.1-04/bin
# 可自行调整配置 nexus.vmoptions 
vi nexus.vmoptions 

2.5、启动服务

必须有JDK环境,该节点已经部署过JDK8环境,此处略过安装JDKJ的步骤;

# 启动命令 &为后台启动:
./nexus run & 也可以改为./nexus start &

2.6、访问页面

http://ip+端口,或者http://ip+端口/nexus3 进入nexus3的管理页面

首次访问页面,点击右上角 Sign In,会提示初始admin的密码文件路径

cat /opt/sonatype-work/nexus3/admin.password

3、创建本地快照仓库

创建maven仓库,用存放本地已经下好的jar包

3.1、选择创建maven仓库

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

3.2、配置仓库的相关信息(仓库名随意)

在这里插入图片描述

3.3、上传JAR包到服务器

将个人PC端本地已经下载好的jar包并上传到Linux服务器上
在这里插入图片描述

# 将仓库打包文件上传到服务上并解压
unzip repository.zip

3.4、创建shell脚本文件

vi mavenimport.sh
#!/bin/bash
# copy and run this script to the root of the repository directory containing files
# this script attempts to exclude uploading itself explicitly so the script name is important
# Get command line params
 
while getopts ":r:u:p:" opt; do
 case $opt in
     r) REPO_URL="$OPTARG"
     ;;
     u) USERNAME="$OPTARG"
     ;;
     p) PASSWORD="$OPTARG"
     ;;
 esac
done
 
find . -type f -not -path './mavenUpload\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;

在这里插入图片描述

3.5、推送jar到私服

# 脚本授权
chmod +x mavenimport.sh
# 执行脚本
./mavenimport.sh -u admin -p Admin123 -r http://172.16.24.163:28081/repository/repository/

3.6、脚本执行完后刷新nexus页面

在这里插入图片描述


4、修改开发环境的镜像来源

修改 apache-maven-3.6.1/conf /settings.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
 
<localRepository>D:/Program Files/repository</localRepository> 
<servers>
    
    <!-- server
     配置私服账号,允许匿名访问忽略了此处
    <server>
      <id>nexus3-mave</id>
      <username>admin</username>
      <password>Admin123</password>
    </server>
    -->  
  </servers>
<mirrors> 
    <!-- 增加maven私服地址 -->
    <mirror>
       <id>nexus3-mave</id>
       <mirrorOf>nexus3-mave</mirrorOf>
       <url>http://172.16.24.163:28081/repository/repository//</url>
    </mirror> 
    
    <!-- 以下是公网maven仓库地址,N网无法使用,暂且保留 -->
   <mirror>
      <id>alimaven</id>
       <name>aliyun maven</name>
       <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
   </mirror>  
   <mirror>
        <id>central</id>
        <name>Maven Repository Switchboard</name>
        <url>http://repo1.maven.org/maven2/</url>
        <mirrorOf>central</mirrorOf></mirror>
    <mirror>
        <id>repo2</id>
        <mirrorOf>central</mirrorOf>
        <name>Human Readable Name for this Mirror.</name>
        <url>http://repo2.maven.org/maven2/</url>
   </mirror> 
   <mirror>
        <id>ibiblio</id>
        <mirrorOf>central</mirrorOf>
        <name>Human Readable Name for this Mirror.</name>
        <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
    </mirror>
    <!-- 中央仓库在中国的镜像 -->
    <mirror>
        <id>maven.net.cn</id>
        <name>oneof the central mirrors in china</name>
        <url>http://maven.net.cn/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
    </mirror> 
  </mirrors>  
</settings>

5"Missing artifact......"的解决办法

在使用Maven开发时,会碰到一些问题,例如“Missing artifact xxx.xxx.jar",而通过下面的方式进行解决。

  • 1、确认本地repository相应目录中是否下载好了对应的包,检查文件大小,尝试删除重新下载;

  • 2、检查maven私服是否有对应的jar,不存在还需上传到私服。(N网开发就这点不方便)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值