Skip to main content

Using JAXB RI's "simpler and better" binding mode from JAX-WS

Posted by kohsuke on January 23, 2007 at 11:37 AM PST

My favorite feature in the JAXB RI is the simpler and better binding mode, which makes the generated code even easier to use, by ...

  1. Eliminating JAXBElement as much as possible
  2. Giving you a better, more typed binding in general
  3. Use plural property names where applicable

My previous entry talks about how to use it from JAXB's xjc tool, but of course you can use it from JAX-WS's wsimport tool, because JAX-WS uses JAXB for the databinding. The following example illustrates how:

<wsimport wsdl="http://www.webservicex.com/stockquote.asmx?WSDL">
  <binding file="simple-binding.xjb" />
</wsimport>

Click the "simple-binding.xjb" link above to download this file, which is pretty short. The binding element can also be an attribute on element if you only have one binding file.

In upcoming JAX-WS RI 2.1, you can also specify any XJC command line options through wsimport ant task. This is handy, for example, for you to use one of the JAXB RI plugins. The following example illustrates how:

<wsimport wsdl="http://www.webservicex.com/stockquote.asmx?WSDL">
  <xjcarg value="-cp"/>
  <xjcarg file="path/to/fluent-api.jar" />
  <xjcarg value="-Xfluent-api"/>
</wsimport>

The element follows the command-line argument mechanism in Ant.

Related Topics >>