如何让本地的项目访问我们的私服

本文详细介绍了Maven在本地项目区下载架包的流程,包括配置本地私服(nexus)和中央仓库,设置个性化下载规则,以及如何设置镜像来优化下载效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

b本地项目区下载架包的时候,顺序是:本地的仓库存储文件夹→本地私服(nexus)→中央仓库

我们可以在maven中的settings.xml中这样设置

  <profiles>
<!--配置我们自己的工厂-->
    <profile>
      <id>nexusProfile</id>
    <repositories>
      <repository>
            <id>test</id>
            <name>nexus</name>
            <url>http://localhost:8081/nexus/content/groups/public/</url>
            <!-- 可以下载releases的架包,默认是打开的 -->
            <releases>
                <enabled>true</enabled>
            </releases>
            <!-- 可以下载snapshots的架包,默认是关闭的 -->
            <snapshots>
                <enabled>
                    true
                </enabled>
            </snapshots>
        </repository>
        </repositories>
    </profile>
    
    
    
    <!--这边重写了central的信息-->
    <profile>
      <id>mycentral</id>
        <repositories>
        <repository>
          <id>central</id>
          <name>Central Repository</name>
          <url>http://rep</url>
          <layout>default</layout>
          <snapshots>
            <!--原本默认是为false。现在修改成了true,架包中的配置就无效了@-->
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>

    </profile>
    
    
    
    
  </profiles>
  <!--进行激活上面的profile-->
  <activeProfiles>
    <activeProfile>mycentral</activeProfile>
  </activeProfiles>

而且我们要设置一个镜像,使得,无论下载什么类型的架包,都会通过这个镜像来去我们本地私服去下载,如果下载不到的话,私服会自动的去中央仓库去下载

<mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
     <!--工厂的镜像,只要mirrorof中的工厂要访问,就会自动来找镜像,如果镜像无法的访问就不会去中央工厂去下载了-->
     <mirror>
      <id>nexusMirror</id>
      <!--使用*表示,所有的都来这边访问,这样的话就可以去掉activeProfiles了-->
      <mirrorOf>*</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://localhost:8081/nexus/content/groups/public/</url>
    </mirror>
     
     
  </mirrors>

 

转载于:https://www.cnblogs.com/fucktom/p/5429039.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值