1,Maven最常用的私服服务器是Nexus;http://www.sonatype.org/nexus/go
2,Nexus提供了两种版本,一种是bundle版本,这个版本包含了nexus的发布应用,同时也包含了各个操作系统需要的服务器,比如对于Java来说,就提供了基于jetty的应用;
3,下载nexus bundle版本:
http://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.9.2-bundle.zip
4,解压到任意文件夹,注意,在nexus-version和sonatype-work两个文件夹都放在一起;
其中:
1,nexus-version:这个文件夹中包含了相关的服务器启动文件;
2,sonatype-work:这个文件夹包含了nexus的配置文件,日志文件和仓库文件等;
5,进入:nexus-2.9.2-bundle\nexus-2.9.2-01\bin\jsw\windows-x86-64文件夹中;
其中:
1,install-nexus.bat:把nexus注册成系统服务;
2,start-nexus.bat:启动nexus(要先执行install-nexus);
3,stop-nexus.bat:停止nexus服务;
4,uninstall-nexus.bat:卸载nexus服务;
5,wrapper.exe:打包的命令行;

这样nexus服务就已经启动了;
查看services.msc,可以看到nexus服务:

默认情况下,nexus服务是开启在8081端口上的,打开浏览器访问:

可以进入到nexus私服的管理页面;
6,当前是处于未登陆状态,很多功能都不能使用,点击右上角登陆:

默认下,超级管理员的账号是admin/admin123;登陆系统后:

就可以使用更多的功能了;
7,对于私服来说,最重要的功能是两个,第一是仓库,第二个是仓库索引;
1,仓库,点击repositories,可以看到nexus内置的仓库;其中比较重要的是:
(1)Maven Central:该仓库代理Maven中央仓库,其策略为Release,因此只会下载和缓存中央仓库中的发布版本构件。
(2)Releases:这是一种策略为Release的宿主类型仓库,用来部署组织内部的发布版本构件。
(3)Snapshots:这是一个策略为Snapshot的宿主类型仓库,用来部署组织内部的快照版本构件。
(4)3rd party:这是一个策略为Release的宿主类型仓库,用来部署无法从公共仓库获得的第三方发布版本构件。
(5)Public Repositories:该仓库组将上述所有策略为Release的仓库聚合并通过一致的地址提供服务。

宿主仓库:maven直接从宿主仓库中下载构件;
代理仓库:maven从代理仓库中下载构件,如果代理仓库中没有构件,则代理仓库从远程仓库下载构件;
仓库组:仓库组是一个虚拟仓库,包含一组宿主仓库和代理仓库;
可以看出区别,1,宿主仓库是本地仓库,是不会去远程下载构件的,所以一般公司内部的构件会放到宿主仓库中;2,代理仓库是可以从远程下载构件的,所以,像中央仓库,或者第三方仓库都可以配置为代理仓库;3,最后,一般会配置一个仓库组供maven统一使用;
2,添加一个仓库组:

页面下面弹出添加仓库组的选项:

添加groupID等:

注意,这里我们只选择了三个仓库,并没有选择apache、codehaus两个代理仓库;这个根据公司需要做配置;
点击保存:

后面的repository path就是访问地址;

可以访问到,但是现在这个仓库组中没有任何内容;
3,更新索引:更新仓库索引,可以从对应仓库的服务器中下载构件索引,我们就可以直接在私服中搜索任何构件了,

点击central仓库,在配置中把download remote indexes设置为true;点击保存;
在central点击右键,选择repair index;即可开始下载中央仓库索引;

中,我们可以看到下载的进度:

8,配置客户端Maven使用私服地址,在.m2的settings.xml里面配置:


配置完成后,在eclipse里面build一个项目,可以看到以下内容:

可以看到,依赖包已经从私服下载了;


网友评论