如何向 OpenDayLight Karaf 添加新功能?

How to add new features to OpenDayLight Karaf?

如何将新功能添加到 ODL Oxygen SR3 (0.8.3) 作为 Karaf 模块?

例如,我从 official page. Then I'd like to make the Toaster sample 下载预构建的 ODL 作为 Oxygen 的新模块,它是使用以下命令创建的:

wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > ~/.m2/settings.xml
mvn archetype:generate -DarchetypeGroupId=org.opendaylight.archetypes -DarchetypeArtifactId=opendaylight-startup-archetype -DarchetypeCatalog=remote -DarchetypeVersion=1.1.0-SNAPSHOT

编译完成后,生成构建文件到本地maven仓库(~/.m2/repository/com/example/toaster)。我将 com/example/toaster 复制到 Karaf 默认存储库文件夹 ./karaf-0.8.3/system。然后我想让它在 feature:list 中可用,这样我就可以使用 feature:install toaster 进行安装。首先,我需要将它添加到回购列表中:

./karaf-0.8.3/bin/karaf
feature:repo-add mvn:com.example.toaster/features-toaster

不幸的是它显示了一个错误:

Error executing command: Error resolving artifact com.example.toaster:features-toaster:jar:0.1.0-SNAPSHOT:

[Could not find artifact com.example.toaster:features-toaster:jar:0.1.0-SNAPSHOT in opendaylight-snapshot (https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/)] : mvn:com.example.toaster/features-toaster

以上命令基于this postrepo-add 的正确做法是什么?

请阅读https://karaf.apache.org/manual/latest/#_artifacts_repositories_and_urls 文章。 您需要做的基本上是将包含您的烤面包机的存储库 URl 添加到包中,如下所示: (上面链接的文档中的示例)

<bundle>http://repo1.maven.org/maven2/org/apache/servicemix/nmr/org.apache.servicemix.nmr.api/1.0.0-m2/org.apache.servicemix.nmr.api-1.0.0-m2.jar</bundle>

也可以使用属性定义存储库:

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

来源:https://karaf.apache.org/manual/latest/#_maven_url_handler

构建后将文件 karaf/target/assembly/etc/org.ops4j.pax.url.mvn.cfg 末尾的配置更改为

org.ops4j.pax.url.mvn.repositories= \
    file:${karaf.home}/${karaf.default.repository}@id=system.repository, \
    file:${karaf.data}/kar@id=kar.repository@multi, \
    https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot@id=opendaylight-snapshot@snapshots, \
    https://nexus.opendaylight.org/content/repositories/public@id=opendaylight-mirror

然后你可以添加一个存储库

feature:repo-add mvn:org.opendaylight.netconf/features-restconf/1.9.0-SNAPSHOT/xml/features

其中 groudId: org.opendaylight.netconfartifactId: features-restconfversion: 1.9.0-SNAPSHOT 取决于您要添加的功能。您可以在 https://nexus.opendaylight.org/ 使用 Articfact Search 搜索它们,并在 Maven pom 中找到它们。