简体   繁体   中英

Does Karaf support downloading of transitive dependencies from 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.

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.

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

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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