Karaf 是否支持从 maven central 下载传递依赖项? [英] Does Karaf support downloading of transitive dependencies from maven central?

查看:30
本文介绍了Karaf 是否支持从 maven central 下载传递依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Karaf,我想知道是否可以将其配置为从 Apache Maven 中央存储库中提取可传递依赖项.无需使用嵌入式捆绑包"

I am trying to use Karaf and I was wondering if it is possible to configure it to pull the transitive dependencies from the Apache Maven Central repository. Without having to use "embedded bundles"

我已经知道您可以提取显式依赖项,问题的关键部分是可传递的"依赖项.

I already know you can pull explicit dependencies, the key part of the the question is the "transitive" ones.

我也知道您可以使用 OBR 读取已部署站点中的 repository.xml 文件,但我找不到用于 Maven 中心的文件.该问题的一个可能答案是添加 URL,但我无法在 repository.xml URL 是什么的任何地方找到它.

I also know you can use OBR to read from a repository.xml file in a deployed site, but I can't find one for Maven central. A possible answer to the question would be to add the URL, but I can't find it documented anywhere what the repository.xml URL is.

目前,我的工作是弄清楚依赖项是什么并将它们显式添加到

At the moment, my work around is to figure out what the dependencies are and explicitly add them to the

嵌入式包不适用于 Karaf OSGi 蓝图实现(它只是等待不存在的东西).我也觉得不得不这样做很丑陋.对于这个问题,我能想到的另一个可能的答案是,是否有创建包的说明,该包可以部署到任何 OSGi 容器(不仅仅是使用 KAR 文件的 Karaf),其中包含所有必要的依赖项.

Embedded bundles do not work with the Karaf OSGi blueprint implementation (it just waits for something that won't exist). I also find it ugly to have to do that. Another possible answer I can think of for this question is if there were instructions to create a package that can be deployed to any OSGi container (not just Karaf using KAR files) that contains all the necessary dependencies.

推荐答案

我找到了一种使用 Maven 以相对 OSGi 标准方式执行此操作的方法.它使用 maven-dependency-plugin 创建一个存储库,该存储库仅包含运行时范围所需的依赖项.

I found a way of doing this in a relatively OSGi standard way using Maven. It uses the maven-dependency-plugin to create a repository that only contains the dependencies that is required on the runtime scope.

然后执行 maven-bundle-plugin:index 目标来创建 repository.xml 文件.

Then the maven-bundle-plugin:index goal is executed to create the repository.xml file.

此时在目标中您有一个有效的 obr 存储库,可根据需要使用 maven-assembly-plugin 对其进行打包.

At this point in the target you have a valid obr repository, the maven-assembly-plugin can be used to package it up as needed.

以下 pom.xml 片段将执行所需的操作.

The following pom.xml snippet will do what is required.

        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-runtime-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <copyPom>true</copyPom>
                        <useRepositoryLayout>true</useRepositoryLayout>
                        <includeScope>runtime</includeScope>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <executions>
                <execution>
                    <id>index</id>
                    <goals>
                        <goal>index</goal>
                    </goals>
                    <phase>verify</phase>
                    <configuration>
                        <mavenRepository>${project.build.directory}/dependency</mavenRepository>
                    </configuration>
                </execution>
            </executions>
        </plugin>

对于 Karaf,可以使用以下命令在不使用 Karaf 的 feature.xml 的情况下安装这个包及其传递依赖项:

As for Karaf, this a bundle along with its transitive dependencies can be installed without using Karaf's feature.xml using the following commands:

features:install obr
obr:addUrl [location of the OBR repository, can be file:///....]
obr:deploy [symbolicname-of-bundle]
start [symbolicname-of-bundle]

瞧.

请注意,这只会加载您指定的包所引用的包,因此如果您使用的是 Blueprint 之类的东西,理论上它不应该知道其他包,那么您必须明确部署它们或创建一个包含您拥有的捆绑包(如功能/产品)的 uber 捆绑包

Note that this will only load up the bundles that are referenced by the bundle you had specified so if you're using something like Blueprint where in theory it shouldn't know about the other bundles, then you have to explicitly deploy them or create an uber bundle that will contain the bundles you have (like a feature/product)

这篇关于Karaf 是否支持从 maven central 下载传递依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆