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

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

问题描述

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

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 Central的文件.这个问题的可能答案是添加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)的OSGi容器的说明. /p>

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之类的产品,那么从理论上讲它不应该了解其他包,那么您必须显式部署它们或创建一个超级捆绑包,其中将包含您拥有的捆绑包(例如功能/产品)

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天全站免登陆