How to build a WSDL using Maven

16,004

I suggest you the cxf maven plugin. I did a small test with this wsdl and it generate and compile successfully (JVM 1.7) 1408 source files. (be patient, it takes a while...)

I only get few warnings about max enum size reached. And so I had to pass a binding file to allow bigger enums. I did it through a binding file. Thanks to this post

Here is the required bind.xml file

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
           xmlns:xsd="http://www.w3.org/2001/XMLSchema"
           jaxb:version="2.0">
    <jaxb:bindings >
        <jaxb:globalBindings typesafeEnumMaxMembers="2000"/>
    </jaxb:bindings>
</jaxb:bindings>

And the relevant part of the pom.xml (as you can see: wsdl and bind.xml are in /src/main/resources)

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>2.7.3</version>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <configuration>
                       <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                        <wsdlOptions>
                            <wsdlOption>
                               <bindingFiles>
                                    <bindingFile>${basedir}/src/main/resources/bind.xml</bindingFile>
                                </bindingFiles>
                               <wsdl>
                                  ${basedir}/src/main/resources/netsuite.wsdl
                               </wsdl>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
Share:
16,004

Related videos on Youtube

Robert H
Author by

Robert H

SOreadytohelp

Updated on June 04, 2022

Comments

  • Robert H
    Robert H almost 2 years

    I'm looking to replace a supplied Ant build with Maven. I know of (but haven't used) ant run, and I'd prefer not too.

    To make a long story short, NetSuite provides a wsdl to use when making web service calls againsts its ERP offering and I currently use their provided ant build to generate the proxy classes from from the wsdl. (sample apps, wsdl and patched axis available here)

    The problem I have is that the ant task uses a patched axis 1.4 (and supporting libraries, several of which are ~7 years old ) and I'd like to implement this wsdl using libraries that are readily available from a central maven repo, and preferably current.

    Can anyone point me where I need to research a solution that will work?

    For any who need to know: I've attempted generating with axis2 and it throws the following exception:

    timeException: Element QName is null for ExceededRequestSizeFault!
            at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGenerationEngine.java:293)
            at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:35)
            at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24)
    Caused by: org.apache.axis2.wsdl.codegen.CodeGenerationException: java.lang.RuntimeException: Element QName is null for ExceededRequestSizeFault!
            at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.emitSkeleton(AxisServiceBasedMultiLanguageEmitter.java:1451)
            at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGenerationEngine.java:275)
            ... 2 more
    Caused by: java.lang.RuntimeException: Element QName is null for ExceededRequestSizeFault!
            at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.getFaultParamElements(AxisServiceBasedMultiLanguageEmitter.java:
    2925)
            at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.getFaultElement(AxisServiceBasedMultiLanguageEmitter.java:2844)
            at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.generateMethodElement(AxisServiceBasedMultiLanguageEmitter.java:
    2366)
            at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.loadOperations(AxisServiceBasedMultiLanguageEmitter.java:2242)
            at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.createDOMDocumentForSkeleton(AxisServiceBasedMultiLanguageEmitte
    r.java:2156)
            at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.writeSkeleton(AxisServiceBasedMultiLanguageEmitter.java:2082)
            at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.emitSkeleton(AxisServiceBasedMultiLanguageEmitter.java:1408)
            ... 3 more
    

    Bonus points if its a tested solution with a recent NetSuite WSDL.

  • Robert H
    Robert H about 11 years
    Thanks Ben, actually I am doing a manual CXF test myself, and am using the exact same binding to handle the enum issue right now :) Thanks for the pom though - it'll be a big help.