Make Serializable JAX-WS clients with Maven2

As I described here I am using JAXWS’ wsimport function to generate a Webservice interface and the JAXB objects for my application. The generated JAXB objects are also used as parameters for some remote EJB calls. Therefore I had to make the JAXB objects serializable. But the question is how to do this since these classes are generated.
Well, in these situations Google is your friend. After a short search I found out to perform the following steps:

  1. Create a binding file and add the xjc:serializable option to it.
  2. It will look like this:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    elementFormDefault="qualified" attributeFormDefault="unqualified"
    jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.1">
        <xs:annotation>
            <xs:appinfo>
                <jaxb:globalBindings>
                    <xjc:serializable />
                </jaxb:globalBindings>
            </xs:appinfo>
        </xs:annotation>
    </xs:schema>

    I name the file ‘jaxb-bindings.xml’ and added it to the resources directory of my Maven project.

  3. Setup the JAX-WS Maven plugin like this:
  4. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    
    ...
    <!-- Plugin to generate JAXB classes and webservice interface -->
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>jaxws-maven-plugin</artifactId>
      <version>1.10</version>
      <executions>
        <execution>
          <goals>
            <goal>wsimport</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <wsdlDirectory>src/main/resources/wsdl</wsdlDirectory>
        <sourceDestDir>${basedir}/generated/src/main/java</sourceDestDir>
        <bindingFiles>
           <bindingFile>${basedir}/src/main/resources/jaxb/jaxb-bindings.xml</bindingFile>
         </bindingFiles>
       </configuration>
       <dependencies>
         <dependency>
           <groupId>javax.jws</groupId>
           <artifactId>jsr181-api</artifactId>
           <version>1.0-MR1</version>
         </dependency>
       </dependencies>
     </plugin>
     ...

    This configuration looks similar to the one I had except of course the ‘bindingFiles’ part.

That’s it! If you generate the sources again by running ‘mvn clean install’ and check the generated files you will see that now they implement the Serializable interface.

tags:

About Pascal Alma

Pascal started as an Oracle Developer in 1997 and developed numerous applications with Oracle Designer/Developer and PL/SQL. Since 2001 Pascal becomes more and more active with the development of software at the Java/J2EE platform. Nowadays Pascal is a senior JEE Developer/ Architect and has a lot of experience with several open source initiatives/ frameworks especially within the Enterprise Integration area. Besides these technical skills Pascal is a big Scrum enthusiastic.

One Response to Make Serializable JAX-WS clients with Maven2

  1. Pingback: Combining Mule with a BPEL Engine | Redstream Blog