Maven搭建nexus服务器学习笔记
如果是公司内部开发,一般都是采用私服来作为中央库。而且官方库国内连接速度非常慢,下载速度只有0点几K每秒,让人很抓狂,使用nexus还可以建立中央库的镜像。
一、安装nexus
nexus官网:http://www.sonatype.com/nexus/product-overview
nexus下载地址:http://www.sonatype.org/nexus/go
这个软件分为多个版本:Nexus OSS、Nexus Pro、Nexus Pro+等。Nexus OSS包含基本仓库管理功能,它是免费的,其余版本要购买授权许可。
1、下载nexus
cd /tmp
wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-latest-bundle.zip
unzip nexus-latest-bundle.zip
mv nexus-2.11.4-01 /home
cd /home/nexus-2.11.4-01/
会解压出nexus-2.11.4-01目录。
2、执行脚本
在nexus-2.11.4-01目录下有这几个目录:
LICENSE.txt NOTICE.txt bin conf lib logs nexus tmp
在bin目录下有一个名为nexus的脚本。
Usage: ./nexus { console | start | stop | restart | status | dump }
执行:
./nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Starting Nexus OSS...
Started Nexus OSS.
3、访问管理页面
浏览器输入:http://IP:8081/nexus/
这种启动方式是使用内嵌jetty的bundle运行,服务器需要安装JDK。jetty是一个运行jsp、servlet的容器,和tomcat类似。
密码:admin123
1、开启远程索引
我们要同步官方的中央库,首先要开启远程索引,下载索引文件。
1)点击Repositories
点击绿色的analyze
在项目的pom.xml中增加:
<repositories> <repository> <id>my-maven</id> <name>My Maven</name> <url>http://IP:8081/nexus/content/repositories/central/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>
这样当本地获取依赖包时会通过私服中央库镜像里下载依赖包。