osgimanifestosgi-bundleosgi-fragment

Which way does Fragment-Host operate with OSGi fragments?


I am having some difficulty getting a fragment to work as I intend. It has raised a question to my mind that is not answered by various articles on the web.

First, my understanding of a fragment is that it is much like an OSGi Bundle except it doesn't activate in its own right; instead it get's hosted by another bundle. In that way, it could be thought of as an extension to an existing bundle.

Somebody please correct the above if wrong.

Now the main question pertains to the Manifest attributes that often go with articles on fragments and specifically, the Fragment-Host attribute. The Fragment-Host attribute is typically declaring a symbolic bundle name, but what is not clear is:

  1. If the manifest attributes containing Fragment-Host is part of existing bundle declaring a fragment that is defined in another module (That is: hosting bundle declares fragment it will host) -OR-
  2. If the manifest attributes containing Fragment-Host are part of the module declaring the fragment, with the value defining the hosting bundle (That is: fragment declares bundle that hosts it) This is the one I believe it is, because "Fragment-Host" sounds like declaring what will host the fragment.

It seems a basic question, but it isn't really answered, and without getting a working example off the ground I am left questioning which way around it is meant to be. Most people who specify that a fragment is needed and "these are what the manifest should look like" are not declaring this sort of simple information that would greatly clarify matters.


Solution

  • It is (2). The fragment bundle has a Fragment-Host manifest header which declares the bundle symbolic name of its host bundle. The fragment bundle is "attached" to the host bundle and class loaded by the host bundle's class loader.