windows搭建maven私服nexus仓库并且上传本地maven库jar包

windows搭建maven私服nexus仓库并且上传本地maven库jar包

一、maven私服仓库nexus搭建

nexus下载

1.首先需要从官网下载nexus安装包
地址:https://www.sonatype.com/download-oss-sonatype
如果无法访问的话,可以用下面分享的链接
链接:https://pan.baidu.com/s/1rfeWSb6wWb3kzekNdHQkqQ
提取码:rwb6

2.下载完成后解压,如下图所示
image

nexus的配置

1.配置运行的端口
在nexus-3.38.0-01-win64\nexus-3.38.0-01\etc目录下的nexus-default.properties文件配置访问端口

image

image

2.配置运行的占用内存
在nexus-3.38.0-01-win64\nexus-3.38.0-01\bin目录下的nexus.vmoptions文件配置内存

image

这里按照需求配置,如果电脑内存比较小,可以配置一个g

nexus的启动

1.第一种方式用cmd命令启动

在开始菜单搜索cmd然后用管理员权限启动,然后进入到nexus安装的根目录下
如图所示:
image

输入

nexus/run

这种方式是在前台运行,当关闭命令提示符后,程序就会停止

输入
nexus/start

这种方式是在后台运行,关闭命令提示符窗口后,程序还会继续运行

输入

nexus/stop

停止程序

2.第二种方式通过windows服务来启动(推荐)
在开始菜单搜索cmd然后用管理员权限启动,然后进入到nexus安装的根目录的bin目录下
输入
nexus/install
注册nexus服务(一定要是管理员权限打开的命令提示符窗口,不然会失败)

在windows服务界面查看

image

将服务启动,显示正在运行就说明服务已经启动了

image

右键该服务打开属性窗口,也可以配置开机自动启动服务,点击停止可停止服务。

nexus登录

image

通过ip+端口访问页面,端口是之前在配置文件中配置的端口

image

点击右上角的sign in按钮登录
用户名默认为admin
nexus3版本初始密码在nexus-3.38.0-01-win64\sonatype-work\nexus3目录下的admin.password文件里
image

image

登录之后会让你修改密码,修改之后,这个文件会被删除

二、本地jar包上传

手动方式上传jar包

在nexus界面点击左边的upload然后选择要上传的仓库
image
选择Jar包上传,然后完善相应信息,点击上传即可
image

使用git命令一次性上传

在本地maven仓库的目录下新建一个.sh文件(我创建的文件名是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}/{} ;

image

在仓库目录右键打开git bash
image

输入以下命令
./mavenimport.sh -u admin -p admin123 -r http://ip:9090/repository/maven-releases/

注意调用sh的文件名、用户名、密码、ip、端口、仓库名都得根据自己的情况修改

image

输入之后按回车键执行即可

上传完毕之后可在仓库中查看上传的jar包
image

image

参考博客:https://blog.csdn.net/weixin_43194885/article/details/116838672
https://blog.csdn.net/lazycheerup/article/details/126060282

posted @ 2022-12-13 14:01  TidalCoast  阅读(337)  评论(0编辑  收藏  举报