0
点赞
收藏
分享

微信扫一扫

局域网搭建Maven私服并批量上传依赖库

数数扁桃 2022-04-14 阅读 63
java后端

局域网搭建Maven私服并批量上传依赖库

使用Nexus3搭建Maven私服

Nexus3下载

百度网盘地址: 密码:zktp

启动Nexus3服务

  1. 解压Nexus

    tar -zxvf nexus-3.29.2-02-unix.tar.gz -C ~/nexus/
    

    解压后~/nexus下目录结构
    在这里插入图片描述

  2. 启动Nexus
    启动命令

    ./nexus-3.29.2-02/bin/nexus start
    

    浏览器访问:http://localhost:8081/
    在这里插入图片描述
    查看admin用户初始密码

    cat sonatype-work/nexus3/admin.password
    

    登陆后会强制修改默认密码,并配置是否选择开启匿名访问。

创建私有仓库

  1. 创建blob商店

  2. 创建储存库

上传本地仓库至私服

Nexus自带上传jar包功能有单个上传页面,如果想批量上传就需要脚本来辅助。

  1. 创建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 './mavenimport.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}/{} ;
    
  2. 将脚本cp至本地Maven库并赋予执行权限

    chmod +x mavenImport.sh
    
  3. 执行导入脚本

    	# 仓库连接为自己创建的仓库地址
    	./mavenImport.sh -u admin -p admin123 -r http://localhost:8081/repository/MyRepository/
    

验证仓库是否上传成功

访问仓库地址http://localhost:8081/repository/MyRepository/,点击HTML index出现树状结构目录则为上传成功
在这里插入图片描述

单个jar包上传

项目使用私服settings文件配置

举报

相关推荐

0 条评论