- 在服务器 /home 目录下,新建一个文件夹 repo,批量放入我们需要的本地库文件夹:
在 repo 文件夹下执行如下命令创建一个 shell 脚本:
vi mavenimport.sh
脚本内容如下: ```shell
!/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}/{} ;
4. 保存退出后执行如下命令赋予其执行权限:
```shell
chmod +x mavenimport.sh
- 执行如下命令即可将该目录下的 jar 包都导入到指定仓库中:
注意:命令中 Nexus 用户名、用户密码、仓库地址根据实际情况进行修改。
./mavenimport.sh -u admin -p 123 -r http://192.168.60.133:8081/repository/my_repo/