Nexus搭建maven私仓

it2026-02-20  6

Nexus建立maven私仓

描述:本文主要是基于Linux系统实现本地jar包上传至nexus私仓

1.Nexus安装

1.1 nexus安装包下载地址

https://www.sonatype.com/nexus/repository-oss/download

1.2 解压

tar -zxvf nexus-3.9.0-01-unix.tar.gz

1.3 启动

cd /home/cc/data/nexus-3.9.0-01/bin/ ./nexus start

1.4 访问nexus仓库管理页面

地址:http://192.168.1.5:8081/ 登录名:admin 密码:admin123

点击登录,按照页面提示填写用户名密码,然后修改默认密码。登录成功后,页面有个红色感叹号,提 示linux系统的文件描述符太小,建议设置大一点。

sudo vi /etc/security/limits.conf #最后添加下面两行 * soft nofile 65536 * hard nofile 65536

重启或切换下用户登录即可生效

#切换用户 su root #查看是否生效,结果应为刚刚修改的65536 ulimit -n

1.5 重启nexus服务

ps -ef|grep nexus #替换pid为对应进程号 kill pid #重启 ./nexus start

2.maven仓库建立

2.1 建立仓库存储目录

本文建一个maven仓库存储目录为例,后续可以为不同的仓库建立不同的存储目录

2.2 配置仓库

2.2.1 maven代理仓库

创建成功。

2.2.2 maven私有仓库

创建成功。

2.2.3 maven仓库组

3.批量上传本地maven依赖jar包

3.1 本地maven仓库同步至服务器

将需要传至nexus私仓的本地maven仓库(包括目录)同步到Linux服务器,本文上传至/home/cc/data/relaese/

3.2 maven仓库本地jar包批量upload

在maven仓库目录即/home/cc/data/relaese/下建立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}/{};

赋予mavenimport.sh执行权限

chmod u+x mavenimport.sh

执行mavenimport.sh文件,格式:./mavenimport.sh -u [用户名] -p [密码] -r [仓库地址]

./mavenimport.sh -u admin -p admin123 -r http://192.168.1.5:8081/repository/credit-chain/

检查nexus仓库是否正确

成功上传至私仓。

4.settings文件修改

<mirrors> <mirror> <id>mynexus</id> <name>mynexus203</name> <url>http://192.168.1.5:8081/repository/maven-group/</url> <mirrorOf>*</mirrorOf> </mirror> </mirrors>

可以看到maven从私仓http://192.168.1.5:8081/repository/maven-group/中拉取依赖jar包。

最新回复(0)