Does Karaf support downloading of transitive dependencies from maven central?

拥有回忆 提交于 2020-01-13 20:40:49

问题


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.

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

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.


回答1:


You can use the karaf-maven-plugin to create a feature file from maven dependencies. This will resolve transitive dependencies.




回答2:


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.

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

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.

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>

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]

And voila.

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)




回答3:


As far as I know, the best you can do is use Maven to download all the dependancies, and then use the Felix bnd plugin to convert your local (or remote) repository into an OBR that you can use with Karaf.



来源:https://stackoverflow.com/questions/10868312/does-karaf-support-downloading-of-transitive-dependencies-from-maven-central

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!