下载地址:https://help.sonatype.com/repomanager3/product-information/download/download-archives—repository-manager-3
可能会导致下载太慢,或者是下载失败 打不开页面,这里推荐使用迅雷下载。
2.2 打开迅雷,使用链接下载
2.3 将安装包上传到linux,并解压(一般放在/usr/local 下)
# 解压安装包
tar -zxvf nexus-3.15.2-01-unix.tar.gz
# 这时会得到 nexus-3.15.2-01、sonatype-work 两个文件夹
# 进入并bin目录下启动nexus
cd nexus-3.15.2-01/bin/
# 启动
./nexus start
以上成功启动!
# 访问 默认端口是8081
http://ip:8081/
# 默认的账号:admin 密码admin123
修改端口,可以去 nexus-3.15.2-01/etc/nexus-default.properties 进行修改
停止nexus
./nexus stop
hosted:本地仓库,通常用来部署自己的构件,比如公司内部的构件
1、maven-release:用于存放release(发行)版本的jar包。
2、maven-snapshots:用于存放snapshots(快照)版本的jar包。
proxy:代理仓库,用来代理远程的公共仓库,可以修改远程仓库的地址(例如使用阿里云仓库)
1、maven-central:代理仓库。
group:仓库组,可用于合并多个仓库(hosted/proxy),方便开发人员设定自己的仓库,当项目中想使用多个repository时,就不需要多次引用,直接引用一个group即可
1、maven-public:仓库组 可添加多个仓库集合,则可以访问多个repository资源。
3.1 设置proxy代理仓库的远程仓库的地址(使用阿里云仓库)
因nexus默认远程仓库很慢,可以改为使用阿里云仓库
阿里云仓库:http://maven.aliyun.com/nexus/content/groups/public
4.1 上传构件到nexus
1、创建一个maven项目
2、在pom.xml 文件中加入以下内容
<distributionManagement>
<!-- 上传到releases的仓库 -->
<repository>
<!--id的名字可以任意取,但在setting文件中属性<server>的id要一致-->
<id>releases</id>
<!-- releases仓库的url -->
<url>http://ip:8081/repository/maven-releases/</url>
</repository>
<!-- 上传到snapshot的仓库 -->
<snapshotRepository>
<id>snapshots</id>
<url>http://ip:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
3、找到maven的setting.xml 配置文件,并在 servers 标签中加入登录nexus的用户名和密码
<!--对应pom.xml repository的id-->
releases</id>
<!-- nexus的账号密码 -->
admin</username>
admin123</password>
</server>
snapshots</id>
admin</username>
admin123</password>
</server>
4.2 修改Maven setting文件(从私服下载依赖)
1、打开setting.xml 配置文件
2、在 mirrors 属性中加入以下内容
<mirror>
<id>nexus-private</id>
<mirrorOf>central</mirrorOf>
<name>Nexus Private</name>
<!-- 更换自己服务器的ip,这里使用的是仓库组,这个仓库组则包含了其他三种类型的仓库 -->
<url>http://ip:8081/repository/maven-public/</url>
</mirror>
3、在 profiles 属性中加入以下内容
<profile>
<id>nexus-remote-private</id>
<!-- 远程仓库列表 -->
<repositories>
<repository>
<id>central</id>
<name>Nexus Private</name>
<!-- 会被镜像拦截 替换成镜像的URL-->
<url>http://ip:8081/repository/maven-public/</url>
<layout>default</layout>
<!-- 表示可以从这个仓库下载releases版本的构件-->
<releases>
<enabled>true</enabled>
</releases>
<!-- 表示可以从这个仓库下载snapshot版本的构件 -->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- 插件仓库列表 -->
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Nexus Private</name>
<url>http://ip:8081/repository/maven-public/</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>
4、增加 activeProfiles 激活profile的配置
<activeProfiles>
<!--需要激活 <profile>中的ID才生效-->
<activeProfile>nexus-remote-private</activeProfile>
</activeProfiles>
成功下载私服的依赖包!