通过maven的中央仓库获取构件是存在很大问题的
- 网速慢,下载jar包时间长,浪费时间
- 不利于公共构件的管理和维护
可以通过搭建Maven私服解决这个问题
- 本地仓库下载速度优于远程仓库下载
- 可自行进行构件的管理和维护
-第三方jar包
-项目模块所依赖的公共构件
Sonatype Nexus
- 强大的Maven仓库管理器,简化了内部仓库的维护和外部仓库的访问
- 不需要数据库,它使用文件系统加Lucene来组织数据
- 官网:https://blog.sonatype.com/
- 两种安装包:
-war 需要自己部署在服务器中运行
-bundle 内嵌jetty容器,可以直接运行 - nexus-2.12.0-01-bundle.tar.gz
-https://www.sonatype.com/download-oss-sonatype
安装环境准备
CentOS 6.4 64位
JDK 1.8
nexus-2.12.0-01-bundle.tar.gz
安装配置
解压tar
tar -zxvf nexus-2.12.0-01-bundle.tar.gz
配置文件 /conf/nexus.properties可以修改nexus的默认端口号8081
启动
- 开启本机8081端口
vim /etc/sysconfig/iptables
- 重启防火墙
service iptables restart
- 配置bin/nexus (RUN-AS-USER=root)
./usr/local/nexus2.12/nexus-2.12.0-01/bin/nexus start
- 默认端口:8081
- 访问:http://ip:8081/nexus/
- 默认用户名/密码:admin/admin123
开启远程索引
Central Repository configuration中
- Download Remote Indexes:true
maven官网的索引下载太大这里使用另一种比较快的方法,在maven官网下载如下文件:
java -jar indexer-cli-5.1.0.jar -u nexus-maven-repository-index.gz -d indexer
将nexus-maven-repository-index.gz解压到indexer文件夹- 停止nexus服务 ./nexus stop
- 删除sonatype-work/nexus/indexer/central-ctx目录下所有文件
rm *
- 将indexer文件夹下的文件拷贝到central-ctx目录
- 重启nexus