目录
一、参考资料
- Nexus Repository Manager OSS 3.x - Windows 安装配置
- windows系统maven私服搭建手册-Nexus Repository Manager OSS 3.x
- Maven 私服 Version policy mismatch, cannot upload SNAPSHOT content to RELEASE repositories for file‘0
二、私服简介
私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件。有了私服之后,当Maven需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载。
三、私服搭建的应用场景
- 局域网环境,不联网的开发;
- 自开发jar包,团队开发需要依赖;
四、 软件及版本选择
1.软件选择
可以使用专门的Maven仓库管理软件来搭建私服,比如:Apache Archiva,Artifactory,Sonatype Nexus。
2.版本选择
目前基本上使用nexus的服务进行私服搭建,nexus最新的版本是3.x,其中有两个版本可供选择:
- Nexus Repository Manager OSS:OSS是Open Source
Software的意思,这个版本包含基于Sonatype 开源软件代码的基本功能和以包形式发布为开源的其他功能,免费试用许可证。 - Nexus Repository Pro:包含了专业版本的所有功能。需要购买许可证。
最新的3.x版本除了支持Maven,还支持Bower,Docker,Git,npm,NuGet等等。
五、下载
本文以Windows 10系统为例,以免费版本oss作为介绍。
Nexus目前支持OS X、Windows和Unix三种平台的安装。
下载地址:https://www.sonatype.com/download-oss-sonatype,选择下载Windows系统对应版本,如图所示:
网盘地址:链接:https://pan.baidu.com/s/1QBlwE-L1DCfDS6vXg_q4BQ 提取码:wi3c
六、搭建
前提:需要配置java jdk环境
1.解压安装包
需注意解压路径不能含有中文、空格等字符,解压后根目录结构如下图所示:
2.服务配置
Nexus需要配置的地方不多,但自带jetty,默认端口8081,可能会有端口冲突,找到配置文件修改即可。
进入.\nexus-3.16.2-01\etc中找到配置文件nexus-default.properties,设置端口和地址,建议修改端口为8181,IP地址修改为实际的本机地址(若是虚拟机,设置为虚拟机静态地址)
端口默认8081,IP默认本机地址
## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
##
# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
nexus-context-path=/
# Nexus section
nexus-edition=nexus-pro-edition
nexus-features=\
nexus-pro-feature
这里的配置,一旦运行nexus程序后,在浏览器输入http://localhost:8081
就可以预览软件的界面及功能了。
3.配置系统环境变量(选择性配置):
可以将Nexus的bin目录(D:\software\Nexus Repository Manager OSS\nexus-3.16.2-01\bin
)添加到Path环境变量中。
4.启动服务
- 查询nexus的命令
进入安装目录的bin文件夹,输入cmd,弹出命令提示符,输入nexus.exe --help
查询nexus的命令:
命令解析D:\software\Nexus Repository Manager OSS\nexus-3.16.2- 01\bin>nexus.exe --help Usage: nexus.exe /install | /uninstall | /stop | /start | /status | /run | /run-redirect
nexus.exe /install 安装服务,将程序安装到系统服务列表 nexus.exe /run 运行服务,将程序启动起来(前台线程启动,退出界面即退出程序) nexus.exe /start 启动服务,将程序以服务的形式启动,将后台调用run进行启动,需等待部分时间完成启动 nexus.exe /stop 停止服务 nexus.exe /status 查看服务状态 nexus.exe /uninstall 卸载服务,在系统服务列表卸载当前服务后,可执行install重新安装
- 直接启动
输入命令:nexus.exe /run
第一次启动比较慢,等打印出Started Sonatype Nexus OSS ...
的内容则启动成功。
如想停止,直接关闭命令窗口就可以停止服务。D:\software\Nexus Repository Manager OSS\nexus-3.16.2-01\bin>nexus.exe /run ... ... ... JettyServer - ------------------------------------------------- Started Sonatype Nexus OSS 3.16.2-01 -------------------------------------------------
- 安装成Windows服务
安装服务,输入命令nexus.exe /install 服务名
。
报错Could not open SCManager.
是因为没有管理员权限。D:\software\Nexus Repository Manager OSS\nexus-3.16.2-01\bin>nexus.exe /install nexus-3.16.2-01 Installed service 'nexus-3.16.2-01'.
启动服务,输入命令nexus.exe /start 服务名
。D:\software\Nexus Repository Manager OSS\nexus-3.16.2-01\bin>nexus.exe /start nexus-3.16.2-01 Starting service 'nexus-3.16.2-01'.
停止Nexus服务nexus.exe /stop 服务名
卸载Nexus服务D:\software\Nexus Repository Manager OSS\nexus-3.16.2-01\bin>nexus.exe /stop nexus-3.16.2-01 Stopping service 'nexus-3.16.2-01'. Service stopped
nexus.exe /uninstall nexus-3.16.2-01
D:\software\Nexus Repository Manager OSS\nexus-3.16.2-01\bin>nexus.exe /uninstall nexus-3.16.2-01 Stopping service 'nexus-3.16.2-01'. Service stopped Uninstalled service 'nexus-3.16.2-01'.
5.访问服务
启动服务后,打开浏览器,输入地址:http://localhost:8181/
点击右上角Sign in,输入账号密码,默认是admin, admin123
。