Declaring your services to OSGi Declarative Services
You can use a separate XML file to declare each service within a bundle.
About this task
The Declarative Services (DS) support operates on declared components, each of which is defined by an XML file in the bundle. When a bundle containing component declarations is added to the framework, DS reads each component declaration and registers provided services in the service registry. DS then manages the lifecycle of the component: controlling its lifecycle based on a combination of declared attributes and satisfied dependencies.
The XML description of components allows DS to resolve service dependencies without requiring the component to be instantiated, or its implementation classes to be loaded. This facilitates late and lazy resource loading, which helps improve server startup and reduce runtime memory footprint.
The XML files that
describe the components are listed in the MANIFEST.MF file
of the bundle using the Service-Component
header,
and by convention are located in the /OSGI-INF directory
of the bundle.
There are a number of tools that can be used to generate the required XML; the following examples show the XML itself.
This topic describes a simple OSGi bundle using XML to declare its components to DS.