简体   繁体   中英

Should library bundle implementing api bundle export the api packages?

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.

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.

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