Skip to content

本地 jar 包导入私服

1. 创建仓库

首先登录到 Nexus 页面,新建一个仓库;

2. 上传本地 jar 包

在服务器上新建一个目录,然后将本地仓库中的 jar 包连同文件目录结构一并上传到服务器上。

3. 新建 shell 脚本

在新建的目录下,新建一个 shell 脚本:

shell
vim 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}/{} ;

保存退出后赋予脚本可执行权限:

shell
chmod +x mavenimport.sh

4. 执行导入

shell
./mavenimport.sh -u admin -p 123456 -r http://127.0.0.1:8081/nexus/content/repository/my_repo/

注意:命令中 Nexus 用户名、用户密码、仓库地址根据实际情况进行修改!

导入完成后,登录 Nexus 控制台,查看是否导入成功。