OSGi and Transitive Dependencies
Asked Answered
B

1

16

I’m using Felix Framework for my OSGi project, but I’ve came across a severe problem concerning third party dependencies.

I’m using eclipse and maven-bundle-plugin to generate my bundles from the sources and the MANIFEST.MF from the POM.XML file. So far so good. however when I have some third party dependency in my bundle, I find myself looking for an infinite list of JARs, which usually are not bundles, and putting them in my /bundle Felix directory until no more dependencies are missing.

I call this process “Downloading the Internet for my OSGi application to work”.

What am I doing wrong? Sure I must be doing something very wrong, because I can’t imagine anyone having a bundle A that depends on B, which then depends on C and D, and then those two will depend on several others and so on… to go look for ALL those dependencies manually using google or maven central! That's insane!

What is the correct way to automate this? I would love to have one of the two solutions:

1) Be able to create a massive JAR file with all of its dependencies embedded, but exporting only the packages I want, and, of corse, not importing any package.

2) (My preferred solution) Having a way to get all my dependencies into individual JAR files that I can simply paste into the /bundle directory.

3) (Even more preferred) Having a way to use third party JARs without downloading 8GB of dependencies to my project.

I have found tools that do me this, but just for direct (1st degree) dependencies, leaving transitive dependencies for me to solve manually.

This problem is critical. The lack of such a tool hampers the usage of OSGi. I’ve searched and searched and searched, I’ve came across all the 101 solutions such as PAX, bndtools, and friends, but it seems that they do not solve this issue…

Please help me. Please provide a living example if you can, people like me around the world will benefit from the solution to this problem.

Thanks!

-

-

Edit: I am attaching a example project where I'm trying to use JScience but the resulting JAR bundle keeps asking me for new Imports, i.e., it is not self-contained.

Link to the example: https://www.dropbox.com/s/svo3nu3vawvv2xn/RequireJscienceExample.zip?dl=0

I usually try to convert 3rd party JARs into bundles using Eclipse, but they always have to Import packages that I do not have, so it is an endless situation as you have stated.

I could not find any documentation concerning the tag Conditional_Package for maven-bundle-plugin. However related searches show me the inline option that I have tried before without success.

I created a basic project where I have one class using JScience library, and in its POM.XML I have the following:

<plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId};singleton:=true
                        </Bundle-SymbolicName>
                        <Bundle-Version>${project.version}</Bundle-Version>
                        <Export-Package>shared.properties.api, shared.properties.base
                        </Export-Package>
                        <Embed-Dependency>!org.osgi.*;scope=compile|runtime;inline=true</Embed-Dependency>
                        <Embed-Transitive>true</Embed-Transitive>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
            </plugin>
</plugins>

I am saying maven to inline all packages which are not from the osgi framework itself. And Looking at the resulting JAR it looks pretty good, I now have embedded only packages instead of entire JARs (however it looks to me that I didn’t need all those inlined packages since I’m using just two of them). Moreover, if I open the MANIFEST.MF file I can see this problematic line:

Manifest-Version: 1.0
Bnd-LastModified: 1414164534170
Build-Jdk: 1.6.0_65
Built-By: Pedro
Bundle-ManifestVersion: 2
Bundle-Name: RequireJscienceExample
Bundle-SymbolicName: RequireJscienceExample;singleton:=true
Bundle-Version: 0.0.1.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Embed-Dependency: !org.osgi.*;scope=compile|runtime;inline=true
Embed-Transitive: true
Import-Package: org.joda.convert,org.xml.sax <------ Problem...
Tool: Bnd-1.50.0

saying that I’m missing org.joda.convert and org.xml.sax.

What amazes me is that we are talking about a library (JScience) that states being OSGi compatible: http://jscience.org/

What am I missing? I really cannot afford not using JScience. And I have rejected several 3rd party libraries before, that would spare me development time, because of these OSGi 3rd party integration difficulties.

Belfort answered 24/10, 2014 at 14:9 Comment(1)
Hey! This is a year old, and not even an attempt to answer! @Belfort What did you end up doing?Merle
E
1

Why not just let Maven to resolve transitive dependency and download them for you.

Once you add them in pom.xml, IDE like Eclipse (m2e plugin actually) can already resolve, download and show resulted jars. (You can use mvn dependency:tree from command line as well)
Then review, and exclude unwanted, e.g. optional or with packages already exported by other bundle.
And yes, use provided scope e.g. for org.osgi.*

<Embed-Dependency>*;scope=compile|runtime;inline=true</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
Empoverish answered 21/4, 2016 at 13:42 Comment(3)
The problem with that is that maven can only go so far in the depth of dependencies. Most dependencies are not bundles and do not have a manifest telling who they depend on. Moreover, several bundles are just monoliths of huge libraries where you only need to use one or two classes but then you end up resolving transitive dependencies for classes you dont need at all (or you open up that bundle and take out the classes you need). For example, try to have an OSGi project using Quartz (quartz-scheduler.org/downloads) where you don't need to mess with transitive dependencies.Belfort
Exactly for quartz, would it be enough <Embed-Transitive>false</Embed-Transitive>Empoverish
For me it wasn't.. far from it.Belfort

© 2022 - 2024 — McMap. All rights reserved.