One of the options for deploying the Web service is to package it as an OSGi bundle and deploy it into an OSGi container such as Red Hat JBoss Fuse. Some of the advantages of an OSGi deployment include:
Bundles are a relatively lightweight deployment option (because dependencies can be shared between deployed bundles).
OSGi provides sophisticated dependency management, ensuring that only version-consistent dependencies are added to the bundle's classpath.
The Maven bundle plug-in is used to package your project as an OSGi bundle, in
preparation for deployment into the OSGi container. There are two essential modifications
to make to your project's pom.xml file:
Change the packaging type to
bundle(by editing the value of theproject/packagingelement in the POM).Add the Maven bundle plug-in to your POM file and configure it as appropriate.
Configuring the Maven bundle plug-in is quite a technical task (although the default settings are often adequate). For full details of how to customize the plug-in configuration, consult Deploying into the OSGi Container and Managing OSGi Dependencies.
The following POM fragment shows a sample configuration of the Maven bundle plug-in, which is appropriate for the current example.
<?xml version="1.0"?> <project ...> ... <groupId>org.fusesource.sparks.fuse-webinars.cxf-webinars</groupId> <artifactId>customer-ws-osgi-bundle</artifactId> <name>customer-ws-osgi-bundle</name> <url>http://www.fusesource.com</url> <packaging>bundle</packaging> ... <build> <plugins> ... <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>${maven-bundle-plugin.version}</version> <extensions>true</extensions> <configuration> <instructions> <Export-Package> !com.fusesource.customer.ws, !com.fusesource.demo.customer, !com.fusesource.demo.wsdl.customerservice </Export-Package> <Import-Package> META-INF.cxf, META-INF.cxf.osgi, * </Import-Package> <DynamicImport-Package> org.apache.cxf.*, org.springframework.beans.* </DynamicImport-Package> </instructions> </configuration> </plugin> ... </plugins> </build> </project>
The Java packages from Apache CXF and the Spring API are imported using dynamic imports
(specified using the DynamicImport-Package element). This is a pragmatic way
of dealing with the fact that Spring XML files are not terribly well integrated with the
Maven bundle plug-in. At build time, the Maven bundle plug-in is not
able to figure out which Java classes are required by the Spring XML code. By listing
wildcarded package names in the DynamicImport-Package element, however, you
allow the OSGi container to figure out which Java classes are needed by the Spring XML
code at run time.
![]() | Note |
|---|---|
In general, using |
After you have configured the POM file, you can build the Maven project and install it in your local repository by entering the following command:
mvn install
To deploy the service bundle, enter the following command at the command console:
karaf@root> install -s mvn:org.fusesource.sparks.fuse-webinars.cxf-webinars/customer-ws-osgi-bundle
![]() | Note |
|---|---|
If your local Maven repository is stored in a non-standard location, you might need
to customize the value of the |
Red Hat JBoss Fuse has a default Jetty container which, by default, listens for HTTP requests on
port 8181. Moreover, WS endpoints in this container are implicitly deployed under the
servlet context cxf/. Hence, any WS endpoint whose address
attribute is configured in the jaxws:endpoint element as
/ will have the following
effective address:EndpointContext
http://Hostname:8181/cxf/EndpointContext
You can optionally customize the default servlet container by editing settings in the following file:
EsbInstallDir/etc/org.ops4j.pax.web.cfgFull details of the properties you can set in this file are given in the Ops4j Pax Web configuration reference..






![[Note]](imagesdb/note.gif)


