tags:

views:

1072

answers:

3

I'm just getting started with OSGI development and am struggling to understand how best to handle dependant JARs.

i.e. if I'm creating a bundle the likelyhood is that I will need to use a few 3rd party JARs. When I create my bundle JAR to deploy to OSGI, obviously these 3rd party JARs are not included and thus the bundle will not run.

I understand that one option is to turn these JARs into bundles and also deploy them to the OSGI container. However if they only need to be used by the one bundle this doesn't seem ideal.

What is the best solution to this? Can the JARs be embedded within the bundle JAR and if so is this a reasonable approach?

+6  A: 

I would almost always bundle each jar separately. OSGi itself is meant for modularization and you take the whole system ad absurdum by not doing this.

If you want to convert JARs into bundles you might want to use the BND Tool written by Peter Kriens. But first I would suggest you look for the bundle in the SpringSource Enterprise Bundle Repository if they haven't already done the work for you.

Roland Schneider
If you are looking for a mainstream open source library, I'd place good money on the Spring guys having it available from their repository.
hbunny
+1  A: 

It is possible to embed non-OSGi dependencies into the bundle.

An easy way to do this is to use Maven to manage your dependencies and Maven Bundle Plugin to build your bundle. Take a look at the <Embed-Dependency> and <Embed-Transitive> instructions of the Maven Bundle Plugin described in the section Embedding dependencies of the plug-in documentation page.

As Roland pointed out this is not an ideal solution with respect to the intentions of OSGi, i.e. modularization and reuse of individual modules. However it might be pragmatic solution for time being until the 3rd-party dependencies can be converted into OSGi bundles.

Pavol Juhos
+7  A: 

You can include a third party jar inside your bundle by adding the third party jar to the root directory of the bundle jar file and then adding a bundle classpath header to the bundle's manifest, e.g.:

Bundle-ClassPath: .;my3rdparty.jar

William
Thought I'd add this answer as it's a solution I found on the web and was able to quickly get working. However I appreciate the opinions with regard to the advantage of properly deploying the JARs as bundles.
William