1 安装jdk
(注:官网要求必须是Oracle的1.8以上的jdk,不能是openjdk)
如果需要切换到Oracle的jdk可参考:https://blog.csdn.net/qq_35720307/article/details/86989781
2 下载nexus
2.1 新建目录nexus后下载压缩包:
wget http://download.sonatype.com/nexus/3/nexus-3.15.2-01-unix.tar.gz
解压:
tar -zxvf nexus-3.15.2-01-unix.tar.gz
解压会有两个文件夹:nexus的 和 sonatype-work。前者是功能的实现,后者负责存储数据
2.2 修改配置:
在目录nexus-3.15.2-01下
修改nexus用户为root: vim bin/nexus.rc => run_as_user="root"
注:
可以修改默认端口:vim etc/nexus-default.properties => application-port=8081
可以修改数据、日志存储位置:vim bin/nexus.vmoptions
2.3 启动:
/nexus/nexus-3.15.2-01/bin/nexus start
访问界面:http://localhost:8081
默认用户名:admin
默认密码:admin123
界面如下:
2.4 nexus界面
已有仓库:
maven-central:maven的中心仓库,nexus这里只是做一个代理,会从maven中心仓库下载各种jar包(不能用于上传)
可以将其Remote storage的地址换成阿里云的镜像地址:http://maven.aliyun.com/nexus/content/groups/public
maven-releases: 这是nexus提供的一个默认的存放我们deploy的 release版本jar包的仓库
maven-snapshots:这是nexus提供的一个默认的存放我们deploy的 snapshot版本jar包的仓库
maven-public:这是一个仓库组,访问这个仓库组的地址其实会访问组内所有仓库(center releases snapshots),我们一般配置私服的远程连接都是配置这个地址
也可以创建新的仓库:
proxy就是代理类,负责转发,比如之前的maven-central;
hosted就是我们常用的存放jar包的仓库,可以选择jar包的类型,release,snapshot或者mixed;
group可以包含多个仓库,比如之前的maven-public;
2.5 使用
maven 的 settings.xml 里增加:
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<properties>
<nexus.ip>http://127.0.0.1:8081</nexus.ip>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
如果项目要deploy到私服,那pom.xml要增加:
<distributionManagement>
<repository>
<id>nexus</id>
<name>Releases</name>
<url>${nexus.ip}/repository/maven-releases</url>
</repository>
<snapshotRepository>
<id>nexus</id>
<name>Snapshot</name>
<url>${nexus.ip}/repository/maven-snapshots</url>
</snapshotRepository>
</distributionManagement>