When should I use Import-Package and when should I use Require-Bundle?

后端 未结 6 1727
醉话见心
醉话见心 2020-12-02 13:58

OSGi allows for dependencies to be determined via Import-Package, which just wires up a single package (exported from any bundle), and Require-Bundle

6条回答
  •  难免孤独
    2020-12-02 14:59

    Favour Import-Package over Require-Bundle.

    Require-Bundle:

    • specifies the explicit bundle (and version) to use. If a requirde bundle needs to be refactored and a package moved elsewhere, then dependents will need changes to their MANIFEST.MF
    • gives you accesss to ALL exports of the bundle, regardless of what they are, and regardless of whether you need them. If the parts you don't need have their own dependencies you will need those to
    • bundles can be re-exported
    • although discouraged, allows the use of split packages, ie: a package that is spread across multiple bundles
    • can be used for non-code dependencies, eg: resources, Help etc.

    Import-Package:

    • looser coupling, only the package (and version) is specified and the run-time finds the required bundle
    • Actual implementations can be swaped out
    • Dependent packages can be moved to different bundles by the package owner
    • But requires more metadata to be maintained (i.e: each package name) at lower levels of granularity

提交回复
热议问题