Share

September 22, 2008

Maven 2 - WSDL TO Java using Jaxb

Step 1:
Download the wsdls and put them in a dir i use "src/main/wsdl", this must match schemaDirectory
Step 2:
Add the following to the build pom.xml

<build>
   <plugin>
    <groupId>com.sun.tools.xjc.maven2</groupId>
    <artifactId>maven-jaxb-plugin</artifactId>
    <executions>
        <execution>
                <id>ws-source-gen</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <schemaDirectory>src/main/wsdl</schemaDirectory>
                    <generateDirectory>src/main/autogen</generateDirectory>
                </configuration>
            </execution>
        </executions>
    </plugin>
....
</build>

Step 3:
Add the autogen dir to the resources

        <sourceDirectory>src/main/java</sourceDirectory>
        <resources>
            <resource>
                <directory>src/main/autogen</directory>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>

Step 4:
I tent do run mvn test to gen the source and run the unit test with the genrated sources

NOTES:
- Don't check in autogen into source countral
After trial and error i learned not to check the auto gen code since you contal the changes to it by checked in the wsdl.

- Exclude autogen code from code covrage
using org.codehaus.mojo to do code covrage i tend to add the following plugin and exclude the auto gencode... so that the reports are clean

<plugin>
 <groupId>org.codehaus.mojo</groupId>
  <artifactId>cobertura-maven-plugin</artifactId>
 <executions>
  <execution>
       <goals>
       <goal>clean</goal>
       </goals>
  </execution>
  </executions>
  <configuration>
  <instrumentation>
       <excludes>
       <exclude>com/company/autogen/**/*.class</exclude>
       </excludes>
  </instrumentation>
  </configuration>
</plugin>