0

I have a big tree of bundles which use other bundles. For example:

  • base bundle uses api bundle.
  • the api bundle is a pure api bundle
  • the base bundle uses the api bundle and is a library bundle (useful library functions, other bundles can use)
  • the api bundle exports the api package
  • the base bundle exports the base package. The base bundle also exports the api packages from the api bundle.

Is it correct to let the base bundle also export the api packages?

I did this because now users only have to add the base bundle to their build path and the base + api bundle is found by bndtools. Otherwise users using the base bundle need to figure out that the base bundle uses the api bundle, which they need to add to the buildpath.

Tinus Tate
  • 2,237
  • 2
  • 12
  • 33

1 Answers1

4

You can export the API packages but you have to make sure that you also import the packages. So the OSGi framework can decide which packages it actually wires. This is important if at some point you have two bundles exporting the same packages.

Btw. Normally you should not export the base package bundles. You do not gain real decoupling if the user of the API still has to know the impl. Instead you can export the impl class as a service with the API interface.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • Thanks for the information @Christian, good to know i'm on the right track. The base bundle is a bit of a special bundle, it is a library bundle, which can be seen as a not so pure api bundle. But sometimes you just have to have a library bundle, for example for offering UI base classes, if not every user would have to create their own UI causing huge code duplication and maintenance problems. – Tinus Tate Feb 18 '16 at 08:31
  • A library bundle is fully ok. You only need services if it is either complicated to instantiate the service or if you want to hide the implementation. – Christian Schneider Feb 18 '16 at 09:48