When is an OSGi fragment attached to host?

前端 未结 2 1684

I have an OSGi bundle with persistence service (using hibernate) and a fragment, which contains configuration (xml file). In bundle\'s activator, I

2条回答
  •  长情又很酷
    2020-12-16 00:56

    Fragments attach to the host at the time that the host is resolved. Normally the fragment will be attached so long as it is installed before the host resolves.

    However there is always the possibility for the host to resolve without the fragment, because hosts do not depend on their fragments. Therefore ordinarily you should write your host so that it can cope with the fragment not being present -- i.e. it should not throw NPEs etc.

    Since OSGi R4.3 you can introduce a dependency from the host onto its fragment using the Require-Capability and Provide-Capability headers. By inventing your own namespace for the dependency you can make your fragment provide it with Provide-Capability. Then your host can require it with Require-Capability.... now the OSGi framework will ensure that the fragment must be available before it resolves the host.

提交回复
热议问题