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 IT consultant and has been working in IT since 1997. He is monitoring the latest development in new technologies (Mobile, Cloud, Big Data) closely and particularly interested in Java open source tool stacks, cloud related technologies like AWS and mobile development like building iOS apps with Swift. Specialties: Java/JEE/Spring Amazon AWS API/REST Big Data Continuous Delivery Swift/iOS
This entry was posted in Maven, Web Service and tagged , . Bookmark the permalink.