jaxbwsdlwsdl2javaxjcxjb

How to generate *.xjb file from WSDL?


I have a WSDL file weatherservice.wsdl and I am trying to generate binding for this WSDL using xjc. How do I do this using xjc?

I did not find any command line args to do it from xjc. xjc -p com -wsdl weatherservice.wsdl


Solution

  • Generally we create a bindings file with .xjb extension to resolve any conflicts in the WSDL or schema. For example if two elements have the same name and you want to distinguish between them you can rename one by specifying it the bindings file.

    Here is an example:

    <jaxb:bindings 
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
        xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
        jaxb:extensionBindingPrefixes="xjc"
        version="2.1">
    
        <jaxb:globalBindings generateIsSetMethod="true" fixedAttributeAsConstantProperty="true">
            <xjc:serializable uid="1" />
        </jaxb:globalBindings>
    
        <jaxb:bindings schemaLocation="abcd.xsd">
            <jaxb:bindings node="//xs:element[@name='Event']/xs:simpleType">
                   <jaxb:typesafeEnumClass name="EventEnumType" />
            </jaxb:bindings>
       </jaxb:bindings>
    
    </jaxb:bindings>