Setting up Ant to build your bundle requires the following:
Setting up the bnd task.
Example 4.2 shows the code for adding the bnd task to Ant.
Example 4.2. Adding BND to Ant
<taskdef resource="aQute/bnd/ant/taskdef.properties" classpath="${cxf.home}/lib/bnd-0.0.249.jar"/>
Adding a target to build the bundle using the bnd task.
Example 4.3 shows the Ant target used to package the WSDL-first demo into a bundle.
Example 4.3. Build Targets for Packaging the WSDL-First Demo as an OSGi Bundle
<target name="osgi" depends="build"> <bnd classpath="${build.classes.dir}" eclipse="false" failok="false" exceptions="true" files="wsdl_first.bnd" output="./build"/> </target>
The wsdl_first.bnd
file provided as the value to the bnd task's
files
property is a BND driver file. The BND driver file controls what is placed in the application's bundle and
it defines the properties that are placed in the application bundle's manifest.
The bnd Ant task uses the BND control file shown in Example 4.4.
Example 4.4. OSGi BND Control File
Private-Package: demo.hw.server, org.apache.hello_world_soap_http.*Import-Package: javax.jws, javax.wsdl, META-INF.cxf, 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, *
Include-Resource: META-INF/spring/beans.xml=beans.xml, hello_world.wsdl=wsdl/hello_world.wsdl
Bundle-Version: 1.0 Require-Bundle: org.apache.cxf.cxf-bundle DynamicImport-Package: org.apache.cxf.*
The BND control file specifies the following:
The classes implementing the service are to be added to the bundle, but not exported. | |
The packages listed in Required packages are imported by the bundle. | |
The WSDL file and the configuration are copied into the proper places in the bundle. | |
The org.apache.cxf.* packages are dynamically imported for the Spring-DM framework. |
For this example, we are going to rely on Spring-DM to publish the endpoint created by the application. Spring-DM requires
that a Spring XML file be placed in the bundle's META-INF/spring
folder. Since FUSE Services Framework
configuration files are Spring XML files, we can simply create FUSE Services Framework configuration file similar to the one shown in
Example 4.5 and have it placed into the proper location in the application's bundle.
Example 4.5. Sample Configuration for an OSGi deployment
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-http.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml" /> <jaxws:endpoint id="hello_world" implementor="demo.hw.server.GreeterImpl" wsdlLocation="hello_world.wsdl" address="http://localhost:9000/SoapContext/SoapPort"/> </beans>
The Include-Resource statement in the BND control file shown in
Example 4.4 instructs BND to copy the configuration file into the bundle's
META-INF/spring
folder.