Avoid generation of WS client with JAXBElement<T>


Avoid generation of WS client with JAXBElement


This recipe explains how to create a JAXB binding file to avoid generating a WS client using wsimport from exposing methods using JAXBElement types (notice, however, that if you need to use them or want to use them, you may use the ObjectFactory class that was generated together with the remaining client code to create the appropriate JAXBElement elements).

How to

I will assume that you are using a maven project here and so the recipe will explain the necessary configuration steps for a maven like project.

First, create the binding file, naming it binding.xjb and put it in src/bindings:

<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
        xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <jaxb:globalBindings generateElementProperty="false" />

Next, you need to configure the jaxws-maven-plugin to use the bindings file:



And that’s it. The previous configurations is what is necessary to avoid exposing JAXBElement type methods. Notice also that the configuration we made with maven forces the wsimport command to use the -b flag, similarly to:

wsimport -keep -s ./generated-sources -d target/classes -Xnocompile \
-wsdllocation http://<wsdlURL>?wsdl -b src/bindings/binding.xjb \

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s