栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

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

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

文章目录
    • linux将本地库JAR批量导入到Nexus3.x
    • 1、问题描述
    • 2、搭建Nexus私服
      • 2.1、官网下载:
      • 2.2、上传并解压
      • 2.3、修改默认端口
      • 2.4、修改内存分配:
      • 2.5、启动服务
      • 2.6、访问页面
    • 3、创建本地快照仓库
      • 3.1、选择创建maven仓库
      • 3.2、配置仓库的相关信息(仓库名随意)
      • 3.3、上传JAR包到服务器
      • 3.4、创建shell脚本文件
      • 3.5、推送jar到私服
      • 3.6、脚本执行完后刷新nexus页面
    • 4、修改开发环境的镜像来源
    • 5`"Missing artifact......"`的解决办法

1、问题描述

(1)由于公司的研发环境迁移到N网的不能联网,不过本地仓库已经有很多的 maven 的 jar 包了,便想将其从本地仓库导入到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



 
D:/Program Files/repository 

    
      
  
 
    
    
       nexus3-mave
       nexus3-mave
       http://172.16.24.163:28081/repository/repository//
     
    
    
   
      alimaven
       aliyun maven
       http://maven.aliyun.com/nexus/content/groups/public/
      central
     
   
        central
        Maven Repository Switchboard
        http://repo1.maven.org/maven2/
        central
    
        repo2
        central
        Human Readable Name for this Mirror.
        http://repo2.maven.org/maven2/
    
   
        ibiblio
        central
        Human Readable Name for this Mirror.
        http://mirrors.ibiblio.org/pub/mirrors/maven2/
    
    
    
        maven.net.cn
        oneof the central mirrors in china
        http://maven.net.cn/content/groups/public/
        central
     
    

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

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

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

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/828625.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号