Create a common xsd generated class to be used by other packages

You can use the -episode extension in the JAXB XJC to handle this use case:

XJC call for common.xsd

xjc -d out -episode common.episode common.xsd

XJC call for objectA.xsd

The episode file produced from the first step is really a JAXB external bindings file that contains links between schema types and existing classes. This prevents XJC from regenerating these classes.

xjc -d out objectA.xsd -extension -b common.episode

For a Detailed Example

  • Can Castor handle class generation from multiple XSDs importing from a base XSD?

There is a part in the maven-jaxb2-plugin documentation dedicated specifically to the separate schema compilation. But you can also achieve your goal with usual XJC bindings.

  • Do not use generatePackage in the plugin config, use jaxb:package in bindings, ex.:

    <jaxb:schemaBindings>
        <jaxb:package name="generatePackage"/>
    </jaxb:schemaBindings>
    
  • Use <jaxb:class ref="com.test.common.CommonType"/> on commonType in xjb/commons.xjb.

SO Disclaimer: I'm the author of the maven-jaxb2-plugin.