I have a couple of XSchema files in my project and all of them include
(at least indirectly) one schema: BasicTypes.xsd
In BasicTypes.xsd I used to have a customized binding:
<xsd:annotation>
<xsd:appinfo>
<jxb:schemaBindings>
<jxb:nameXmlTransform>
<jxb:typeName prefix="JAXBGen"/>
<jxb:elementName prefix="JAXBGen"/>
<jxb:modelGroupName prefix="JAXBGen"/>
</jxb:nameXmlTransform>
</jxb:schemaBindings>
</xsd:appinfo>
</xsd:annotation>
so all classes generated by xjc will have a prefix of 'JAXBGen' - which
works fine on Win2K and Mac OS X. But on Linux the prefix is missing on
the generated java sources. It turned out, that on Win2K and Mac OS X
xjc first processes BasicTypes.xsd but on Linux LocatorTypes.xsd (which
includes BasicTypes.xsd) is processed first:
win2k> xjc
win2k> Compiling file:/ ... /BasicTypes.xsd
vs.
linux> xjc
linux> Compiling file:/ ... /LocatorTypes.xsd
In my ant-script xjc ist called this way:
<xjc target="${jaxb-generated-src}" package="${jaxb-package}">
<schema dir="${xschema}" includes="*.xsd"/>
</xjc>
where ${xschema} is the directory that contains all schema files. So it
seems that the order xjc processes its input files is platform or
file-system dependant and if the custom-binding is not in the first
xschema processed the binding will not be taken into account.
Since external bindings now work with JAXB 1.0 final I modified the
ant-script to call xjc like this:
<xjc target="${jaxb-generated-src}" package="${jaxb-package}">
<binding file="${xschema}/jaxb-external-bindings.xjb"/>
<schema dir="${xschema}" includes="*.xsd"/>
</xjc>
jaxb-external-bindings.xjb looks like this:
<jxb:bindings version="1.0"
xmlns:jxb="
http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="
http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="BasicTypes.xsd" node="/xsd:schema">
<jxb:schemaBindings>
<jxb:nameXmlTransform>
<jxb:typeName prefix="JAXBGen"/>
<jxb:elementName prefix="JAXBGen"/>
<jxb:modelGroupName prefix="JAXBGen"/>
</jxb:nameXmlTransform>
</jxb:schemaBindings>
</jxb:bindings>
</jxb:bindings>
but since I have to specify a schemaLocation (BasicTypes.xsd) the same
problem occurs again. My current workaround is that I duplicated the
binding for BasicTypes.xsd with a reference to LocatorTypes.xsd. Now
xjc works fine on all three platforms.
Is it possible to specify bindings for all xsd-files that xjc will
process?
Maybe this is a bug in xjc or somewhere in the libs dealing with xml
and xsd?
Any ideas for a better workaround?
Best regards,
Stefan
PS: I strongly recommend to use ant 1.5.2 with JAXB's xjc task it
seems to fix a nasty problem with xjc reporting strange errors.