maven 之中央仓库和私有仓库实战

最好的资料是这篇文章:Maven3实战笔记09Maven的私服-Nexus常用功能 - 琉璃仙境 - ITeye技术网站
http://suhuanzheng7784877.iteye.com/blog/1073768

下面我只是记了一个笔记而已:

当中央仓库不可用访问的时候,可以设置如下。
只要在我们的 pom 文件中设置了下面的片段,maven 就会帮我们从下面配置片段的 url 中去下载构建。

<repositories>
        <repository>
            <id>central</id>
            <name>Central Repository</name>
            <url>http://mirrors.ibiblio.org/maven2/</url>
            <layout>default</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

参考的远程 maven 仓库的地址:
默认远程的地址:
http://repo1.maven.org/maven2/

nexus的:
https://nexus.sourcesense.com/nexus/content/repositories/public/

开源中国:http://maven.oschina.net/content/groups/public/

最后试了一下,用下面这个仓库地址就可以了:
http://mirrors.ibiblio.org/maven2/

这个片段的格式是可以抄的:
在本地 maven 文件的 D:\app\apache\apache-maven-3.3.3\lib 文件夹里的
maven-model-builder-3.3.3.jar\org\apache\maven\model 文件。
这里写图片描述

私有仓库的设置

配置私有仓库以后,我们在 maven 项目里配置 GAV 的时候,就会看到 maven 从我们的私服下载构件了。

下面我们介绍一下私有仓库的设置:
1、先更新私有仓库的索引
这里写图片描述
这样做,须要耐心等待一段时间。
我们也可以用下载好的索引文件(Lucene 索引文件)覆盖到 nexus 的相应位置。

D:\app\nexus-2.8.1-01-bundle\sonatype-work\nexus\indexer\central-ctx

2、设置镜像:让所有的请求都从私服发出去
配置在 .m2 文件夹下的 settings.xml 文件下。

<mirror>
      <id>central</id>
      <mirrorOf>*</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://192.168.0.116:8081/nexus/content/groups/public/</url>
    </mirror>

3、配置 profile

说明:配置了镜像以后,profile 的 url 意义就不是很大了。

<profile>
      <id>central-repo</id>
      <repositories>
        <repository>
          <id>central</id>
          <name>Central-repo</name>
          <url>http://central</url>
          <releases><enable>true</enable></releases>
          <snapshots><enable>true</enable></snapshots>
        </repository>
      </repositories>
    </profile>

4、将 profile 节点激活

<activeProfiles>
    <activeProfile>central-repo</activeProfile>
  </activeProfiles>

这里写图片描述

说明:有时候还须要配置代理。

<proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>192.168.0.116</host>
      <port>8081</port>
    </proxy>  

参考资料:
maven download jar Could not transfer artifact - - ITeye技术网站
http://chinahnzhou.iteye.com/blog/1343267

使用maven镜像 - 推酷
http://www.tuicool.com/articles/VRJ3qui

Maven镜像配置 - xun_2008的专栏 - 博客频道 - CSDN.NET
http://blog.csdn.net/xun_2008/article/details/16916801

黑暗中漫步的博客:使用nexus搭建maven私服
http://blog.csdn.net/happyteafriends/article/details/7451061

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值