There are a number of tools available and the different OSGi containers use varying deployment mechanisms. However, the basic steps to package and deploy applications into an OSGi container are the same:
Determine how the application will publish its endpoints.
In order for your application to be started by the OSGi framework it needs to have logic that instantiates the resources used by the application. For a JAX-WS server application this means that the service provider endpoints need to be created and published. For a JAX-WS client application this means that the object implementing the client's business logic needs to be instantiated. The application may also need some logic to clean up its resources when shutting down.
There are two ways to get the resources for your application started:
rely on Sring-DM to publish the endpoints
publish the endpoints in a BundleActivator object
Decide how you want to bundle the application.
Depending on the complexity of you application, it may make sense to break your application into several bundles. You will also want to be very deliberate in determining if your application's bundles include any third party libraries.
![]() | Tip |
|---|---|
The best practice is to find OSGi bundles containing all of the third party libraries needed by your application and use the OSGi dependency mechanism to resolve them. |
Create bundles for each of your application's modules.
Install the bundles to the container.
Once your bundles are installed, you can start and stop them using the container's commands. You can also upgrade them in place when needed.
Spring Dynamic Modules for OSGi Service Platforms(Spring-DM) scans bundles in an OSGi container and automatically creates
a Spring application context for any bundles that contains a Spring XML file in its
META-INF/spring folder. It will inject all of the beans defined in the configuration file into the
application context. For JAX-WS server, you would include a jaxws:endpoint element for each service
provider your application exposes. Spring-DM injects them into the application context and publish the endpoints when the bundle is
started.
Before using Spring-DM you must make sure the required bundles are installed into your OSGi container. You must also make sure they are started. FUSE ESB and include support for Spring-DM as part of their default configuration. If your container does not include Spring-DM support you can download it from http://www.springsource.org/osgi.
![]() | Important |
|---|---|
When using Spring-DM to publish endpoints you must include the following DynamicImport-Package statement in the bundle's manifest: DynamicImport-Package: org.apache.cxf.* This allows the Spring framework to construct the proper FUSE Services Framework objects. |
The org.osgi.framework .BundleActivator is an OSGi API used by the OSGi framework when
it starts and stops bundles. As shown in Example 4.1, it has two methods that need to
be implemented.
Example 4.1. Bundle Activator Interface
interface BundleActivator
{
public void start(BundleContext context)
throws java.lang.Exception;
public void stop(BundleContext context)
throws java.lang.Exception;
}The start() method is called when the container starts the bundle. This is where you would
instantiate and publish any service provider endpoints exposed by a server application. For a client application, this is the method
that would instantiate the client's application logic.
The stop() method is called when the container stops the bundle. This is where you would
stop any endpoints exposed by a server.
When using a bundle activator you need to add the Bundle-Activator property to the bundle's manifest. This property tells the container which class in the bundle to use when activating the bundle.
For more information on publishing service provider endpoints see
Publishing a Service in
You can hand edit the manifest files for each of your application's bundles and manually assemble them using the standard Java mechanism for creating JARs. Hand editing a manifest is a tedious and error prone process and is not recommended. You should use one of the many tools available for creating OSGi bundles.
The bnd tool from Peter Kriens is powerful and freely available. It automates the construction of OSGi bundle manifests by introspecting the contents of the classes being packaged in the bundle. Using the knowledge of the classes contained in the bundle, the tool can calculate the proper values to populate the Import-Packages and the Export-Package properties in the bundle manifest.
The bnd tool can be used as an Ant task and is the foundation for the Maven bundle plug-in from Apache Felix.
The FUSE Services Framework core components are included in an OSGi bundle called
org.apache.cxf.cxf-bundle.
![]() | Tip |
|---|---|
FUSE ESB and install the |
FUSE Services Framework applications depend on a number of runtime packages. Because of the complex nature of the dependencies in FUSE Services Framework, you cannot rely on the bnd tool to automatically determine the needed imports. You will need to explicitly declare them.
You need to import the following packages into your bundle:
javax.jws
javax.wsdl
META-INF.cxf
META-INF.cxf.osgi
org.apache.cxf.bus
org.apache.cxf.bus.spring
org.apache.cxf.bus.resource
org.apache.cxf.configuration.spring
org.apache.cxf.resource
org.springframework.beans.factory.config