搭建maven私服
nexus的安装及配置
 使用nexus工具来搭建maven私服。nexus有两个大版本:2.*,3.*。
 下载nexus:https://www.sonatype.com/download-nexus-repo-oss,下载时请选择OSS版本(免费)。
 nexus的安装:
 nexus是一个压缩版的软件,解压即可使用,解压目录中不能有中文和空格。
 环境变量的配置:
 在用户变量的path中添加:nexus的解压目录\nexus-3.9.0-01-win64\nexus-3.9.0-01\bin。
 启动nexus:在命令行中输入nexus.exe /run,出现以下界面代表启动成功:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-63NC2AKv-1609121077223)(nexus启动成功的标志.png)]
 验证:http://localhost:8081,nexus默认端口为8081。
 安装成功后,nexus默认提供了用户名和密码:
- 用户名:admin
 - 密码:admin123
 
 nexus的仓库类型:
- proxy:代理仓库,最常用的就是maven的中央仓库。
 - hosted:本地仓库。
 - 3rd party:第三方仓库(oracle的JDBC)。
 
 nexus提供的3个仓库和1个仓库组:
- maven-central:maven中央仓库。
 - maven-releases:maven的release项目部署到私服时,存放的仓库。
 - maven-snapshots:maven的snapshot项目部署到私服时,存放的仓库。
 - maven-public:仓库组
 
 修改nexus中央仓库镜像
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6mzRo8j5-1609121077239)(修改neuxs中央仓库镜像1.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-euh2jgfc-1609121077244)(修改neuxs中央仓库镜像2.png)]
nexus的使用
使用私服进行依赖
 在maven的settings.xml进行以下配置即可:
<mirror>
    <id>nexus-woniu</id>
    <mirrorOf>*</mirrorOf>
    <name>Nexus woniu</name>
    <url>http://localhost:8081/repository/maven-public/</url> 
</mirror>
 注:如果失败,可以将maven-central指向的中央仓库镜像改成:http://maven.aliyun.com/nexus/content/repositories/central
将项目部署到私服中
 在maven的settings.xml进行以下配置:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <servers>
    	<server>
      		<id>nexus</id>
      		<username>admin</username>
      		<password>admin123</password>
    		</server>
    </servers>
</settings>
 在nexus中将maven-releases和maven-snapshots的hosted设置为allow redeploy。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-yAuMkwo6-1609121077251)(maven-releases的hosted设置.png)]
 在要部署到nexus中的项目的pom.xml中,使用<distributionManagement>设置项目要存放的nexus仓库。
<distributionManagement>
    <!-- 对应nexus中maven-releases -->
    <repository>
      <id>nexus</id>
      <name>nexus-release</name>
      <url>http://localhost:8081/repository/maven-releases/</url>
    </repository>
    <!-- 对应nexus中maven-snapshots -->
    <snapshotRepository>
      <id>nexus</id>
      <name>nexus-snapshot</name>
      <url>http://localhost:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
  </distributionManagement>
 注意:<distributionManagement>的<repository>的id值必须与maven的settings.xml中的<server>的id值匹配,否则失败。
无论你在学习上有任何问题,重庆蜗牛学院欢迎你前来咨询,联系QQ:296799112
                  
                  
                  
                  
                            
                            
本文介绍了使用nexus工具搭建maven私服的方法,包括下载、安装、环境变量配置、启动和验证等步骤,还说明了nexus的仓库类型和默认提供的仓库及仓库组。此外,讲解了如何使用私服进行依赖以及将项目部署到私服中的具体配置。
          
      
          
                
                
                
                
              
                
                
                
                
                
              
                
                
              
            
                  
					
					443
					
被折叠的  条评论
		 为什么被折叠?
		 
		 
		
    
  
    
  
            


            