繁体   English   中英

Karaf是否支持从Maven Central下载传递依赖项?

[英]Does Karaf support downloading of transitive dependencies from maven central?

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

我已经知道您可以拉出显式依赖关系,问题的关键部分是“传递性”依赖关系。

我还知道您可以使用OBR从已部署的站点中的repository.xml文件中进行读取,但是找不到用于Maven Central的文件。 这个问题的可能答案是添加URL,但在任何repository.xml URL所在的地方都找不到文档。

目前,我的解决方法是找出依赖项是什么并将其显式添加到

嵌入式捆绑软件不适用于Karaf OSGi蓝图实现(它只是在等待不存在的东西)。 我也觉得必须这样做。 另一种可能的答案,我可以为这个问题想的是,如果有提示创建一个包含所有必要的依赖,可以部署到任何 OSGi容器(不只是Karaf使用KAR文件)封装。

您可以使用karaf-maven-plugin从maven依赖项创建功能部件文件。 这将解决传递依赖性。

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

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

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

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

        <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,可以使用以下命令安装此捆绑包及其传递依赖项:

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

和瞧。

请注意,这只会加载您指定的包所引用的包,因此,如果您使用的是Blueprint之类的产品,那么从理论上讲它不应该了解其他包,则必须显式部署它们或创建一个超级捆绑包,其中将包含您拥有的捆绑包(例如功能/产品)

据我所知,最好的办法是使用Maven下载所有依赖项,然后使用Felix bnd插件将本地(或远程)存储库转换为可与Karaf一起使用的OBR。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM