一,去Nexus官网下载最新的安装包,我下载的是nexus-2.11.2-04-bundle.zip
二,解压文件到硬盘的根目录
我把解压出来的两个文件放在了nexus文件夹中。
根据目录依次进入如下图的目录,根据自己机器是64位还是32位选择
选择install-nexus.bat右键以管理员身份运行,将nexus进行安装上,选择start-nexus.bat右键以管理员身份运行,nexus会启动,显示如下界面
启动完毕没有报错的话,此界面会自动关闭。
三。登陆nexus,打开浏览器输入http://localhost:8081/nexus/回车,即进入如下界面
在右上角会有login按钮,点击登陆 账号admin密码admin123
登陆后左边一栏显示如下图
点击Repository,会看到如下图显示
nexus的仓库类型分为以下四种:
group: 仓库组
hosted:宿主
proxy:代理
virtual:虚拟
首次登陆nexus后可以看到以下一个仓库组和多个仓库。
Public Repositories: 仓库组
3rd party: 无法从公共仓库获得的第三方发布版本的构件仓库
Apache Snapshots: 用了代理ApacheMaven仓库快照版本的构件仓库
Central: 用来代理maven中央仓库中发布版本构件的仓库
Central M1 shadow: 用于提供中央仓库中M1格式的发布版本的构件镜像仓库
Codehaus Snapshots: 用来代理CodehausMaven 仓库的快照版本构件的仓库
Releases: 用来部署管理内部的发布版本构件的宿主类型仓库
Snapshots:用来部署管理内部的快照版本构件的宿主类型仓库
点击type类型为proxy的
会在下方弹出一个tab栏
将Download Remote Indexes设置为true,然后保存,这样代理会通过网络下载网络上的索引,这样在查找jar文件时自动搜索。
四 创建Nexus代理仓库
点击Add按钮选Proxy Repository
会出现如下窗口
RepositoryID和RepositoryName是必填项,根据自己要添加的maven代理仓库的名字命名即可,
Remote Storage Location为仓库镜像地址 例如中央仓库的为https://repo1.maven.org/maven2/,根据需要填写别的即可,然后保存
五,将创建的代理仓库添加到仓库组
点击publicRepository 选择configuration选项卡,将available repository中的仓库添加到Ordered Group Repository中,点击保存
Ordered Group Repository中的仓库从上到下是检索顺序,因此要将Releases放在最上面,将代理仓库放下面,这样在搜索的时候
先去releases中去查找有没有需要的,没有再去代理库中查找,找到后下载到本地。
这样nexus就可以使用了
六,修改maven配置文件,进行使用nexus仓库
在maven的配置文件setting.xml的响应位置进行如下设置
//设置需要登录的用户名和密码
<servers>
<server>
<id>my-nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>my-nexus-snapshot</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers><mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.1.122:8081/nexus/content/groups/public</url>//将ip换成对应的自己的本地iP
</mirror>
</mirrors><profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>//激活nexus配置
</activeProfiles>
这样使用maven就可以了。
以上是自己在搭建自己的本地maven服务时,自己通过查资料和摸索搭建的,如有什么问题,请大家指正。