最近本地搭建了windows版的nexus,批量上传jar时出现问题,找遍了博客和资料,基本都是linux版本的,终于找到了这篇文章,写的挺好,亲测可用,在此记录一下
“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}/{} ;
前提:windows执行shell脚本,务必安装git 客户端工具。
1)mavenimport.sh需要在maven库目录下,如下图
Maven目录(待上传jar包集目录):F:\10Primeton_STUDIO\40eos_v5.0\00_PrimetonRepository
2)打开Git Bash 客户端命令工具,开始执行命令,如下图:
3)打开的窗口中,执行如下命令 :
./mavenimport.sh -u admin -p admin123 -r http://你的ip:你的端口/repository/自己新建仓库的名称
例:./mavenimport.sh -u admin -p admin123 -r http://127.0.0.1:8081/repository/local-maven-hosted/
4)浏览器 打开Nexus3.x,查看仓库下的上传的jar包信息:
5)上传前Maven仓库和上传后Nexus3.x对比图: