tags:

views:

265

answers:

2

I have a CommonTypes.xsd which I'm including in my all other XSDs using xs:include. I get

Multiple <schemaBindings> are defined for the target namespace ""

when I try to compile it into different packages using binding files. Please tell me whether there is a way to compile them into different packages. I'm using jaxb 2.1

A: 

Hi,

I've meet the same problem and haven't solve it yet, but I'm afraid that it can't be possible to generate XSD into differents packages :

It is not legal to have more than one <jaxb:schemaBindings> per namespace, so it is impossible to have two schemas in the same target namespace compiled into different Java packages

from Compiler Restrictions at the end of this page

but if some one find some work around, just inform us please

LE GALL Benoît
A: 

Yeah, there is a way.
Assuming:

xsd/common/common.xsd
xsd/foo/foo.xsd 

In the common directory place common.xjb:

<jxb:schemaBindings>
    <jxb:package name="mypkg.common">
    </jxb:package>
</jxb:schemaBindings> 

In the foo directory place foo.xjb:

<jxb:schemaBindings>
    <jxb:package name="mypkg.foo">
     </jxb:package>
</jxb:schemaBindings> 

In the build.xml file, create one xjc task for each:

<xjc destdir="${app.src}" readOnly="true" package="mypkg.common">
    <schema dir="${app.schema}/common" includes="*.xsd" />
    <binding dir="${app.schema}/common" includes="*.xjb" />
</xjc>
<xjc destdir="${app.src}" readOnly="true" package="mypkg.foo">
    <schema dir="${app.schema}/foo" includes="*.xsd" />
    <binding dir="${app.schema}/foo" includes="foo.xjb" />
</xjc>

You need to make sure that common.xsd has a targetNameSpace that is different from foo.xsd's targetNameSpace.

Shantanu