Search code examples
javaxsdjaxbjaxb2maven-jaxb2-plugin

Multiple <schemaBindings> are defined for the target namespace when defining package


I have 3 XSD's in my project. Two in the namespace "A" and one in namespace "B".

I want to generate XSD-1, XSD-2 (same namespace) into one package. Then generate XSD-3 in to an different package.

I am trying to do this via the bindings.xjb file.

If I declare

<jxb:bindings schemaLocation="xsd1-namespaceA.xsd">
    <jxb:schemaBindings>
        <jxb:package name="com.xsdPrimary" />       
    </jxb:schemaBindings>
</jxb:bindings>

<jxb:bindings schemaLocation="xsd2-namespaceA.xsd">
    <jxb:schemaBindings>
        <jxb:package name="com.xsdPrimary" />               
    </jxb:schemaBindings>
</jxb:bindings>

<jxb:bindings schemaLocation="xsd3-namespaceB.xsd">
    <jxb:schemaBindings>
        <jxb:package name="com.xsdSecondary" />             
    </jxb:schemaBindings>
</jxb:bindings>

Then I get the error:

com.sun.istack.SAXParseException2: Multiple <schemaBindings> are defined for the target 
namespace "http://www.jeff-test.org/namespaceA/"

If I remove the first two entries in the bindings file, then the generation works, but it puts all my classes in a package called "jeff-test.namespaceA" for namespaceA and all those from namespaceB in the package "com.xsdSecondary".

I want all the classes from namespace-A into one package and all those from namespace-B into another package.

Is this possible?


Solution

  • Multiple are defined for the target namespace "http://www.jeff-test.org/namespaceA/"

    If I remove the first two entries in the bindings file, then the generation works, but it puts all my classes in a package called "jeff-test.namespaceA" for namespaceA...

    Just remove just one of the entries for namespaceA. What's the logic behind removing both?

    <jxb:bindings schemaLocation="xsd1-namespaceA.xsd">
        <jxb:schemaBindings>
            <jxb:package name="com.xsdPrimary" />       
        </jxb:schemaBindings>
    </jxb:bindings>
    
    <jxb:bindings schemaLocation="xsd3-namespaceB.xsd">
        <jxb:schemaBindings>
            <jxb:package name="com.xsdSecondary" />             
        </jxb:schemaBindings>
    </jxb:bindings>
    

    schemaBindings is considered once per namespace, it does not matter which schema file is it bound to (as long as this file is a part of the compilation).