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:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs=""
    elementFormDefault="qualified" attributeFormDefault="unqualified"
    jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.1">
                    <xjc:serializable />

    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. ...
    <!-- Plugin to generate JAXB classes and webservice interface -->

    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.

About Pascal Alma

Pascal is a senior software developer and architect. Pascal has been designing and building applications since 2001. He is particularly interested in Open Source toolstack (Mule, Spring Framework, JBoss) and technologies like Web Services, SOA and Cloud technologies. Lately he is having great fun by building iOS apps with Swift. Specialties: JEE AWS XML/XSD/XSLT Web Services/SOA Mule ESB/ WSO2 ESB Maven Cloud Technology Swift/ iOS
This entry was posted in Maven, Web Service and tagged , . Bookmark the permalink.