Search code examples
jax-wscxfprefix

Add prefix to the classes generated by cxf


I use CXF to generate Java classes form wsdl. Is it possible to assign a prefix to all generated classes names?


Solution

  • The wsdl2java tool has an -b option:

    -b | binding-name | Specifies JAXWS or JAXB binding files or XMLBeans context files. Use multiple -b flags to specify multiple entries.

    The binding file you provide needs to have the following contents:

    <jxb:bindings version="1.0"
      xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
      jxb:extensionBindingPrefixes="xjc">
    
        <jxb:bindings schemaLocation="../xsd/schema.xsd" node="/xs:schema">
            <jxb:schemaBindings>
                <jxb:nameXmlTransform>
                    <jxb:typeName prefix="Foo"/>
                    <jxb:anonymousTypeName prefix="Foo"/>
                    <jxb:elementName prefix="Foo"/>
                </jxb:nameXmlTransform>
            </jxb:schemaBindings>
        </jxb:bindings>
    </jxb:bindings>
    

    This adds Foo prefix to classes generated for types, anonymous types and elements. Note that the schemaLocation attribute must point to the actual schema.