Maven入门教程(十四)-Nexus3.X私服下载资源

本章节主要讲解如何将私服的资源下载到本地仓库。

从图中我们可以看到,当我们设置了私服后,系统会先在私服中查找是否有需要的资源,如果没有则去远程仓库查找。

具体如何设置私服呢?步骤如下

首先我们需要在maven目录下的config目录下的setting.xml文件中配置私服信息

添加镜像信息,将所有外网仓库的请求指向私服:

 

<mirror>
	  <id>nexus</id>
	  <mirrorOf>*</mirrorOf>
	  <url>http://localhost:8081/repository/maven-public/</url>
	</mirror>

此处的url我们配置的是group类型的仓库组

这样我们的私服就会按照group仓库组里配置的私服地址依次查找资源是否存在

 

添加仓库的配置

 

<profile>
      <id>nexus</id>
		<!--所有请求均通过镜像 -->
      <repositories>
        <repository>
			  <id>central</id>
			  <name>Central Repository</name>
			  <url>https://repo.maven.apache.org/maven2</url>
			  <layout>default</layout>
			  <snapshots>
				<enabled>true</enabled>
			  </snapshots>
    </repository>
      </repositories>
	  <pluginRepositories>
			<pluginRepository>
			  <id>central</id>
			  <url>https://repo.maven.apache.org/maven2</url>
			  <releases>
				<enabled>true</enabled>
			  </releases>
			  <snapshots>
				<enabled>true</enabled>
			  </snapshots>    
			</pluginRepository>
  </pluginRepositories>
    </profile>

生效配置信息,activeProfile的值要和profile中的id内容一致

<activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>

这样我们私服的配置就完成了,完整的setting.xml文件如下

<?xml version="1.0" encoding="UTF-8"?>
<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">

  <pluginGroups>
  </pluginGroups>

  <proxies>
  </proxies>
  <servers> 
 
  </servers>
  <mirrors>

	<mirror>
	  <id>nexus</id>
	  <mirrorOf>*</mirrorOf>
	  <url>http://localhost:8081/repository/maven-public/</url>
	</mirror>
	
  </mirrors>

  <profiles>
	 <profile>
      <id>nexus</id>
		<!--所有请求均通过镜像 -->
      <repositories>
        <repository>
			  <id>central</id>
			  <name>Central Repository</name>
			  <url>https://repo.maven.apache.org/maven2</url>
			  <layout>default</layout>
			  <snapshots>
				<enabled>true</enabled>
			  </snapshots>
    </repository>
      </repositories>
	  <pluginRepositories>
			<pluginRepository>
			  <id>central</id>
			  <url>https://repo.maven.apache.org/maven2</url>
			  <releases>
				<enabled>true</enabled>
			  </releases>
			  <snapshots>
				<enabled>true</enabled>
			  </snapshots>    
			</pluginRepository>
  </pluginRepositories>
    </profile>

  </profiles>

   <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值