2.1. Customizing Java packages

The JAXB specification provides a <jaxb:schemaBindings> customization so that you can control which namespace goes to which package. See the example below:

package customization

      <jaxb:package name="org.acme.foo"/>

You can do this as an internal customization (in which case you put this in <xs:annotation><xs:appinfo> under place it right under the <xs:schema> element), or do this as an external customization, like this:

External package customization

<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1">
  <bindings schemaLocation="../path/to/my.xsd">
      <package name="org.acme.foo"/>

Note that this customization is per namespace. That is, even if your schema is split into multiple schema documents, you cannot put them into different packages if they are all in the same namespace.

2.1.1. Tip: get rid of the org.w3._2001.xmlschema package

Under some rare circumstances, XJC will generate some Java classes into a package called org.w3._2001.xmlschema. This happens when XJC decides that it needs some Java artifacts for the XML Schema built-in namespace of http://www.w3.org/2001/XMLSchema.

Since this package name is most often problematic, you can rename this by simply saving the following text in an .xsd file and submitting it to XJC along with the other schemas you have:

Schemalet to get rid of org.w3._2001.xmlschema
<schema xmlns="http://www.w3.org/2001/XMLSchema"
      <jaxb:package name="org.acme.foo"/>

This is bit tricky, but the idea is that since you can define a schema for one namespace in multiple schema documents, this makes XJC think that this schema is a part of the built-in "XML Schema for XML Schema".

Terms of Use; Privacy Policy; Copyright ©2013-2017 (revision 20160708.bf2ac18)
Please Confirm