Sunday 6 April 2014

WSDL2Java using CXF and Maven

This short post will show how to generate client classes for java web service client using Apache CXF and Apache Maven. Lets assume that you have your project set up and your WSDL file ready so all you need to do is to add the below plugin into your pom.xml maven configuration into plugins section.

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>${cxf.version}</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-bindings-soap</artifactId>
            <version>${cxf.version}</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>generate-jaxb</id>
            <phase>generate-sources</phase>
            <configuration>
                <additionalJvmArgs>-Dfile.encoding=UTF8</additionalJvmArgs>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>src/main/resources/wsdl/YourWsdlFile.wsdl</wsdl>
                        <extraargs>
                            <extraarg>-wsdlLocation</extraarg>
                            <extraarg></extraarg>
                            <extraarg>-client</extraarg>
                            <extraarg>-p</extraarg>
                            <extraarg>com.yourcompany.types</extraarg>
                        </extraargs>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

That's it. Your java classes from WSDL file will be generated into: ${project.home}\target\generated-sources\cxf directory.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.