Can OSGi fragments have other fragments as hosts?

1.2k Views Asked by At

Is this legal?

MANIFEST.MF for org.fragment1 (org.host is a normal bundle, not a fragment):

Bundle-SymbolicName: org.fragment1
Fragment-Host: org.host

MANIFEST.MF for org.fragment2:

Bundle-SymbolicName: org.fragment2
Fragment-Host: org.fragment1

Or should org.fragment2 instead have

Fragment-Host: org.host

?

2

There are 2 best solutions below

3
On BEST ANSWER

Fragment bundles can't have a other fragment bundles as host. Only normal bundles can act as an fragment-host. So your third example is correct:

Or should org.fragment2 instead have

Fragment-Host: org.host

You find this restriction in the OSGi Service Platform Release 4 Version 4.3 Core Specification on page 70. It says:

A Fragment bundle can not be required by another bundle with the Require-Bundle header.

0
On

Fragments attach to hosts. They cannot attach to other fragments. You can construct capabilities and requirements (new in Core 4.3) to prevent a fragment from attaching to a host unless another fragment is also attached. For example, fragment 1 could provide a capability which fragment 2 requires. This may provide the level of control you seek.