Nexus安装、使用说明、问题总结
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Nexus安装、使⽤说明、问题总结
Nexus安装、使⽤说明、问题总结
1 . 私服简介
私服是架设在局域⽹的⼀种特殊的远程仓库,⽬的是代理远程仓库及部署第三⽅构件。
有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载。
我们可以使⽤专门的 Maven 仓库管理软件来搭建私服,⽐如:,,。
这⾥我们使⽤ Sonatype Nexus。
2 . 安装Nexus
2 . 1 . 下载Nexus
Nexus 专业版是需要付费的,这⾥我们下载开源版 Nexus OSS。
Nexus 提供两种安装包,⼀种是包含 Jetty 容器的 bundle 包,另⼀种是不包含容器的 war 包。
下载地址:。
2 . 2 . 使⽤bundle安装包安装Nexus
解压安装包nexus-2.8.1-bundle.zip,打开命令提⽰符,进⼊/nexus-2.8.1-01⽬录,键⼊nexus命令(为⽅便启动和退出Nexus,可将bin⽬录添加到环境变量):
执⾏ nexus install 将Nexus安装为Windows服务。
可将服务启动⽅式设为⼿动,以后通过 nexus start 即可启动Nexus ,通过 nexus stop 退出Nexus:
打开浏览器,访问:http://localhost:8081/nexus/:
点击右上⾓ Log In,使⽤⽤户名:admin ,密码:admin123 登录,可使⽤更多功能:
3 . Nexus预置的仓库
点击左侧 Repositories 链接,查看 Nexus 内置的仓库:
Nexus 的仓库分为这么⼏类:
hosted 宿主仓库:主要⽤于部署⽆法从公共仓库获取的构件(如 oracle 的 JDBC 驱动)以及⾃⼰或第三⽅的项⽬构件;
proxy 代理仓库:代理公共的远程仓库;
virtual 虚拟仓库:⽤于适配 Maven 1;
group 仓库组:Nexus 通过仓库组的概念统⼀管理多个仓库,这样我们在项⽬中直接请求仓库组即可请求到仓库组管理的多个仓库。
4 . 添加代理仓库
以 Sonatype 为例,添加⼀个代理仓库,⽤于代理 Sonatype 的公共远程仓库。
点击菜单 Add - Proxy Repository :
填写Repository ID - sonatype;Repository Name - Sonatype Repository;
Remote Storage Location - /content/groups/public/ ,save 保存:
将添加的 Sonatype 代理仓库加⼊ Public Repositories 仓库组。
选中 Public Repositories,在 Configuration 选项卡中,将 Sonatype Repository 从右侧 Available Repositories 移到左侧 Ordered Group Repositories,save 保存:
5 . 搜索构件
为了更好的使⽤ Nexus 的搜索,我们可以设置所有 proxy 仓库的 Download Remote Indexes 为 true,即允许下载远程仓库索引。
索引下载成功之后,在 Browse Index 选项卡下,可以浏览到所有已被索引的构件信息,包括坐标、格式、Maven 依赖的 xml 代码:
有了索引,我们就可以搜索了:
6 . 配置Maven使⽤私服
私服搭建成功,我们就可以配置 Maven 使⽤私服,以后下载构件、部署构件,都通过私服来管理。
在 settings.xml ⽂件中,为所有仓库配置⼀个镜像仓库,镜像仓库的地址即私服的地址(这⼉我们使⽤私服公共仓库组 Public Repositories 的地址):
<mirrors>
<mirror>
<id>central</id>
<mirrorOf>*</mirrorOf> <!-- * 表⽰让所有仓库使⽤该镜像-->
<name>central-mirror</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>
</mirrors>
PS1:私有maven仓库Nexus使⽤http与https协议
Http协议:没有问题
Https协议:
Could not GET 'https://some_/some/path/some.pom'.
> peer not authenticated
解决:
If you get any other error like this:
Could not GET 'https://some_/some/path/some.pom'.
> peer not authenticated
Then you need to import a certificate:
open the '' in your favorite browser
export the cert using the
copy the cer into JDK_HOME/jre/lib/security folder
open a shell and go to JDK_HOME/jre/lib/security folder
then import the cer into java using the
keytool -import -alias <the short name of the server> -file <cert_file_name_you_exported.cer> -keystore cacerts -storepass changeit
It will prompt you to import the certificate, type yes and press enter.
Then restart your eclipse and try building the project.。