【Maven】搭建Nexus Maven私有仓库
来源:互联网 发布:网络棋牌赌博平台 编辑:程序博客网 时间:2024/05/14 03:45
- 私有仓库原理
- 私有仓库好处
- 搭建私有仓库
- 使用私有仓库
Maven作为目前主流的项目管理工具,在依赖管理、系统构建等方面的表现可谓可圈可点。但对于去“墙内”用户而言,访问国外的Maven仓库无疑是一场噩梦,搭建私有Maven仓库是解决该问题的有效途径之一。
私有仓库原理
- 开发人员或构建系统基于本地的Maven构件(artifact)库进行系统构建;
- Maven本地库将项目自建构件发布到Maven私有库中实现发布共享和版本管理,并从Maven私有库中加载本地所需的依赖;
- 如果Maven私有库中不存在所需构件,则扫描所配置的外部中央仓库或镜像进行下载,再下载到本地库,二次使用时无需再次从外部下载构件。
私有仓库好处
- 一劳永逸:将构件先下载到位于内网环境私有仓库,后续使用无需重复到国外或镜像下载,解决外网速度和带宽占用问题,提升开发效率;
- 自建构件发布和共享:可以将项目的构件发布到私有仓库,从而实现模块化项目管理。
搭建私有仓库
Nexus 是Maven仓库管理器,还提供了强大的仓库管理功能、构件搜索功能,它基于REST,友好的UI是一个extjs的REST客户端,它占用较少的内存,基于简单文件系统而非数据库。这些优点使其日趋成为最流行的Maven仓库管理器。
本节将介绍如何在Linux环境下搭建私有Nexus Maven仓库。
注:Nexus 3.*当前最新版本3.2.1需要在JVM1.8及更高版本环境运行,本文使用的 Nexus版本为2.14.3,详细内容请参见官方文档。
- 安装JDK:【转载】使用RPM在Linux环境安装JDK 1.7
- 下载Nexus:https://www.sonatype.com/download-oss-sonatype
安装Nexus:
将压缩包上传到服务器,并解压获得两个目录:tar -zxvf nexus-2.14.3-02-bundle.tar.gz
- nexus-2.14.3-02是nexus服务主目录;
- sonatype-work是真正的仓库,同时包含了nexus的配置,如定时任务、用户配置等。
修改启动端口
Nexus默认端口为8081
,建议修改为其他端口,修改nexus/conf/nexus.properties
配置文件即可。启动Nexus
执行以下命令启动:/app/nexus/nexus-2.14.3-02/bin/nexus start
如出现
Root
用户异常和解决方案如下图:
nexus
命令用法如下:
nexus { console | start | stop | restart | status | dump }
登录控制台
控制台地址如下,端口与配置文件nexus.properties
一致:http://10.0.79.28:8081/nexus/
登录页面如下:
默认登录名/密码为admin / admin123
管理仓库(Repository)
仓库分类:- hosted——本地仓库,通常我们会部署自己的构件到这一类型的仓库;
- Releases :存放Maven中提交的Releases项目
- Snapshots :存放Maven中提交的Snaphots项目
- 3rd party :存放Maven中央仓库中没有的第三方jar包
- proxy——代理仓库,它们被用来代理远程的公共仓库,如maven中央仓库;
- virtual——虚拟仓库,是Nexus中配置的另一个仓库的逻辑视图;
- group——仓库组,用来合并多个hosted/proxy仓库,通常我们配置maven依赖仓库组。
- hosted——本地仓库,通常我们会部署自己的构件到这一类型的仓库;
管理hosted仓库
新增代理仓库
http://repo1.maven.org/maven2
http://maven.aliyun.com/nexus/content/groups/public/
http://maven.oschina.net/content/groups/public/
http://repository.jboss.com/nexus/content/repositories/root_repository/maven2/
http://maven.springframework.org/release下载远程索引
将新增代理加入到仓库组
管理仓库组
使用私有仓库
在单独项目中使用
配置项目的pom.xml
文件如下:<repositories> <repository> <id>nexus</id> <name>Nexus Repository</name> <url>http://localhost:8081/nexus/content/groups/public/</url> </repository></repositories>
其中
<url>
标签为以下内容:本地Maven全局使用
配置Maven配置文件settings.xml
如下即可:<profiles> <profile> <id>nexus</id> <repositories> <repository> <id>nexus</id> <name>local private nexus</name> <url><Your Nexus IP>/nexus/content/groups/public</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>nexus</id> <name>local private nexus</name> <url>http://<Your Nexus IP>/nexus/content/groups/public-snapshots</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>local private nexus</name> <url>http://<Your Nexus IP>/nexus/content/groups/public</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> <pluginRepository> <id>nexus</id> <name>local private nexus</name> <url>http://<Your Nexus IP>/nexus/content/groups/public-snapshots</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> ... <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles>
这时候记得在eclipse里选择对应的profile
上传构建到私有仓库
配置Maven配置文件settings.xml
如下:<settings> ... <servers> <server> <id>nexus-releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin123</password> </server> </servers> ... </settings>
配置工程
pom.xml
配置文件如下:
<project> ... <distributionManagement> <repository> <id>nexus-releases</id> <name>Nexus Release Repository</name> <url>http://<Your Nexus IP>/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <url>http://<Your Nexus IP>/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement> ... </project>
两个配置文件中的id
必须一致,执行如下命令即可:
mvn deploy
参考:
1. Nexus 搭建maven 私有仓库
2. Maven零散笔记——配置Nexus
- Nexus 搭建maven 私有仓库
- Nexus搭建Maven私有仓库
- Nexus搭建Maven私有仓库
- Nexus搭建私有maven仓库
- Nexus 搭建maven 私有仓库
- 【Maven】搭建Nexus Maven私有仓库
- 使用Nexus搭建Maven私有仓库
- centos使用nexus搭建私有maven仓库
- Nexus 私有仓库搭建与 Maven 集成
- [Sonatype Nexus]Ubuntu、Nexus搭建Maven私有仓库
- Nexus 搭建 Maven 仓库
- Maven-----搭建Nexus仓库
- Maven 私有仓库搭建
- 搭建Maven私有仓库
- 用nexus搭建自己的maven私有仓库
- maven私服:用nexus搭建企业级私有仓库
- maven私有仓库搭建之sonatype nexus篇
- 使用Gradle和Sonatype Nexus 搭建私有maven仓库
- 泛型
- jvm笔记8--虚拟机字节码执行引擎
- Ubuntu 文件管理器死掉
- 二层交换机/三层交换机/路由器
- git的入门和基本操作
- 【Maven】搭建Nexus Maven私有仓库
- cv::Mat与CvMat理解
- 求两个整数的最大公约数
- linux驱动开发之module导出符号
- 枚举
- docker mysql utf8mb4 编码问题解决方法
- Linux之groupdel和userdel
- vector—— String Manipulation 1.0
- L1-009. N个数求和