LibraryLink ToToggle FramesPrintFeedback

Packaging a Web Service in a Bundle

This section explains how to modify an existing Maven project for a Apache CXF application, so that the project generates an OSGi bundle suitable for deployment in the Fuse ESB OSGi container. To convert the Maven project, you need to modify the project's POM file and the project's Spring XML file(s) (located in META-INF/spring).

To configure a Maven POM file to generate a bundle, there are essentially two changes you need to make: change the POM's package type to bundle; and add the Maven bundle plug-in to your POM. For details, see Modifying an Existing Maven Project.

The Apache CXF runtime components are included in Fuse ESB as an OSGi bundle called org.apache.cxf.bundle. The dependency on this bundle can conveniently be expressed by adding the Require-Bundle element to the Maven bundle plug-in's instructions, as highlighted in the following sample POM:

<project ... >

In order for your application to use the Apache CXF components, you need to import their packages into the application's bundle. Because of the complex nature of the dependencies in Apache CXF, you cannot rely on the Maven bundle plug-in, or 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:

Example 7.1 shows how to configure the Maven bundle plug-in in your POM to import the mandatory packages. The mandatory import packages appear as a comma-separated list inside the Import-Package element. Note the appearance of the wildcard, *, as the last element of the list. The wildcard ensures that the Java source files from the current bundle are scanned to discover what additional packages need to be imported.

The OSGi Configuration Admin service defines a mechanism for passing configuration settings to an OSGi bundle. You do not have to use this service for configuration, but it is typically the most convenient way of configuring bundle applications. Both Spring DM and Blueprint provide support for OSGi configuration, enabling you to substitute variables in a Spring XML file or a Blueprint file using values obtained from the OSGi Configuration Admin service.

For details of how to use OSGi configuration properties, see Use OSGi configuration properties (optional) and Add OSGi configurations to the feature.