maven私服nexus搭建

时间:2022-10-22 09:06:56

(一)nexus安装
1. 安装nexus
下载的私服文件nexus-2.12.0-01-bundle.zip 解压
maven私服nexus搭建
在命令提示符下,进入此目录,敲入命令
nexus install
如有下列提示则证明安装成功
maven私服nexus搭建
如果想卸载,命令为:
nexus uninstall
2. 启动nexus
在服务中找到nexus ,右键启动
maven私服nexus搭建
3. 进入nexus
打开浏览器输入地址:http://localhost:8081/nexus
maven私服nexus搭建
点击右上角的 Log In ,在弹出窗口中输入 username 为 admin , password 为
admin123,点击LogIn按钮
(二)构建索引
刚刚安装好的nexus是无法直接搜索到jar包的,必须下载索引才可以正常使用。
我们到*仓库地址 http://repo.maven.apache.org/maven2/.index/ 下载以下两
个索引压缩文件
nexus-maven-repository-index.gz
nexus-maven-repository-index.properties
这两个文件一般在此页面的最后的位置,另外还需要在网上下载一个名为indexer-cli-5.1.1.jar 的jar包
将以下三个文件放入一个文件夹
maven私服nexus搭建
cmd执行:
java-jarindexer-cli-5.1.1.jar-unexus-maven-repository-index.gz-dindexer
执行后生成目录indexer,目录下的文件是索引文件,如下图
maven私服nexus搭建
将 D:\nexus-2.12.0-01-bundle\sonatype-work\nexus\indexer\central-ctx 目录下的文
件删除,将上边的索引文件拷贝到此目录下。
拷贝后重新启动nexus,然后进入nexus搜索jar包发现可以进行搜索了。
maven私服nexus搭建
(三)仓库类型
maven私服nexus搭建
1、hosted:宿主仓库,自己项目的jar要放到hosted类型的仓库中。
2、proxy:代理仓库,代理*仓库
3、virtual:虚拟仓库,存储了maven1的构件,一般不用。
4、group:仓库组,将一些仓库组成一个组,自己项目连接仓库组去下载jar包。
平常开发中都去连接仓库组,仓库组中包括:hosted、proxy等。
仓库所在的文件夹见下面的截图:
maven私服nexus搭建
(四)镜像配置
nexus已经安装好了,我们要开始使用它了。现在我们需要在maven的配置文件settings.xml中配置镜像,让maven找私服,而不是直接到*仓库下载。
打开maven的配置文件settings.xml,添加如下配置:

<mirrors> 
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf> <url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>
</mirrors>

mirrors为镜像组,可以配置多个mirror(镜像) ,我们这里配置的是nexus中的*代理仓库。配置好后,我们需要创建一个项目来测试一下,看看是不是可以通过nexus来下载jar包。
测试步骤:
创建 maven 工程(jar),在 pom.xml 中添加依赖,观察 nexus 中是否下载了相应的jar包,目录为 nexus-2.12.0-01-bundle\sonatype-work\nexus\storage\central