【JAVA】对karaf的maven远程仓库的配置

引言

       初次接触ODL的时候,对于外部feature的部署真的是绞尽脑汁,因为在网上搜相关的博客很少,于是我便硬着头皮去看官方文档了,最终找到了满意的答案。

核心概念

       1、 一个feature=一组bundle;所以feature不是额外的软件,只是定义了一个xml文件描述这个依赖于哪些bundle或者是feature,所以feature在仓库里只提供一个xml文件下载;

       2、 类似于mvn:org.opendaylight.dlux/odl-dlux-core/0.7.5/xml/features的url结构,mvn代表了仓库的根目录,以http(s)开头,org.opendaylight.dlux/odl-dlux-core/0.7.5/xml/features代表了文件夹的目录结构;

       3、需要的feature文件可以在ODL的中央仓库查找(https://nexus.opendaylight.org/#nexus-search),找到对应feature之后查看定义的xml文件,复制如下地址供repo-add调用:(注:中央仓库非常好用,远程仓库配好后,想要什么查什么)

Maven URL Handler

       Maven URL Handler是karaf的maven url的解析器(就是用来解析mvn:org.opendaylight.dlux/odl-dlux-core/0.7.5/xml/features这类东西的),它也是一个bundle,原文是这么说的:

        The org.ops4j.pax.url.mvn bundle resolves mvn URLs. It can be configured using the file etc/org.ops4j.pax.url.cfg. Full reference of org.ops4j.pax.url.mvn PID configuration can be found on pax-web Wiki page.

The most important property is:

  • org.ops4j.pax.url.mvn.repositories : Comma separated list of remote repository URLs that are checked in order of occurence when resolving maven artifacts

Two other significant properties are:

  • org.ops4j.pax.url.mvn.defaulRepositories : Comma separated list of locations that are checked before querying remote repositories. These can be treated as read-only repositories, as nothing is written there during artifact resolution.

  • org.ops4j.pax.url.mvn.localRepository : by default (implicitly) it’s standard ~/.m2/repository location. This local repository is used to store artifacts downloaded from one of remote repositories, so at next resolution attempt no remote request is issued.

       简单的来说原文说了这么几个概念:

       1、Maven URL Handler是名叫org.ops4j.pax.url.mvn的bundle;

       2、Maven URL Handler可以通过karaf的etc目录下的org.ops4j.pax.url.cfg文件进行配置

      3、有这么三个配置项:

                    1)org.ops4j.pax.url.mvn.repositories 用来配置远程仓库,可以配置多个,用逗号分隔

                    2)org.ops4j.pax.url.mvn.defaulRepositories 用来配置只读的本地仓库,会在查找远程仓库之前查找,可以配置多个,用逗号分隔

                    3)org.ops4j.pax.url.mvn.localRepository 用来配置本地仓库,默认用的是~/.m2下的仓库,从远程仓库下载的构件会保存在这个仓库,下一次就直接从本地仓库读取,这是三个仓库里最先查找的一个,只能配置一个。

问题解决

        我就配置了远程仓库(配置文件见上文),配置仓库如下:

       配置完成之后,我启动karaf,调用repo-add命令,repo-add mvn:org.opendaylight.dlux/odl-dlux-core/0.7.5/xml/features完成feature的安装。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值