Venkatesh Laguduva
Venkatesh Laguduva

Reputation: 14408

OSGi bundle picks up the system bundle over the specified bundle

One of our bundle has 'imports' on joda-time/2.2.0 but when I start it,it always picks up the joda-time/1.6.2 available in the system folder of Karaf. I am not sure how can that happen? is there a way to tell the karaf not to pick the system bundle over the one specified by us? please note that we drop bundles to deploy folder to get them installed.

Upvotes: 0

Views: 190

Answers (2)

Marcel Offermans
Marcel Offermans

Reputation: 3323

First of all, make sure you really need two versions of this bundle. Yes, you can make that work but in general, unless you really need different versions of bundles to be present within your application, avoid it. Check what bundles consume joda-time and what version ranges they specify in their Import-Package statement.

I'm not sure if you're aware of this, but if you import a package, you always, either implicitly or explicitly specify a version range you are compatible with:

  • If you don't specify any version, you effectively state you're compatible with a version range from zero to infinity.
  • If you specify only one version, you state you're compatible with that version and anything higher than that, up to infinity.
  • If you specify two versions, you state you're compatible with that range and you can either use square or round brackets to state if this includes or excludes the borders.

Not specifying a range explicitly is considered bad practice. OSGi has a whitepaper on semantic versioning that explains this in more detail.

So, make sure you understand what versions your bundles that consume joda-time use, see if you can deploy just one implementation of joda-time and ensure that your own bundle also uses a version range that is compatible with that.

Upvotes: 1

Oliver
Oliver

Reputation: 6260

Just add the version you need to import after the package you are importing like this.

Import-Package: org.xx.xx;version=1.5.0

Refer this

Upvotes: 0

Related Questions