Fork me on GitHub

Using JAXB XJC plugins with wsimport

JAX-WS uses JAXB for data binding through the XJC binding compiler. A feature of XJC is its extensibility, which can be used to enhance the generated code via XJC plugins. Below is an example of this by using the JAXB2 Basics plugins.

<project>
  ...
  <dependencies>
    ...
    <!-- to compile xjc-generated sources -->
    <dependency>
      <groupId>org.jvnet.jaxb2_commons</groupId>
      <artifactId>jaxb2-basics-runtime</artifactId>
      <version>0.6.4</version>
    </dependency>
  </dependencies>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>2.5</version>
        <dependencies>
          <!-- put the XJC plugins on the jaxws-maven-plugin's classpath -->
          <dependency>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>jaxb2-basics</artifactId>
            <version>0.6.4</version>
          </dependency>
        </dependencies>
        <configuration>
          <!-- tell JAXB to actually use the XJC plugins -->
          <xjcArgs>
            <xjcArg>-Xequals</xjcArg>
            <xjcArg>-XtoString</xjcArg>
          </xjcArgs>
        </configuration>
        <executions>
          <execution>
            <id>jaxws-wsimport</id>
            <goals>
              <goal>wsimport</goal>
            </goals>
          </execution>
          <configuration>
            <wsdlUrls>
              <wsdlUrl>http://footballpool.dataaccess.eu/data/info.wso?WSDL</wsdlUrl>
            </wsdlUrls>
          </configuration>
        </executions>
      </plugin>
    </plugins>
    ...
  <build>
  ...
</project>