Defining package names for common XSD's with xjc and bindings

firstpimp

New Member
I'm trying to generate Java classes from several specific XSD's with \[code\]xjc\[/code\]. Those schemas have some definitions in common, so they import a number of common XSD's. In particular, they can include from zero to all of the common XSD's. I'd like to generate all classes from an specific XSD to a specific package, but keeping the generated classes for the common schemas in a common package, so they don't get repeated for each specific schema in the source tree.I've learnt that custom bindings can be used to specify packages on a per-schema basis, with for instance: \[code\]<jxb:bindings schemaLocation="common1.xsd" node="/xsd:schema"> <jxb:schemaBindings> <jxb:package name="mypackage.commonclasses"/> </jxb:schemaBindings></jxb:bindings>\[/code\]I've got the following structure: \[code\]schemas| - common| | - common1.xsd --> XSD with common types #1| | - ...| | - commonN.xsd --> XSD with common types #N| | - commonBindings.xjb --> Defines package "mypackage.commons" for common*.xsd| - specific1| | - specific1.xsd --> Includes ../common/common{1-N}.xsd| | - specific1.xjb --> Defines package "mypackage.specific1" for specific1.xsd| - specificN| | - specificN.xsd --> Includes only ../common/common1.xsd| | - specificN.xjb --> Defines package "mypackage.specificN" for specificN.xsd\[/code\]It all works fine with: \[code\]xjc -b schemas/specific1 -b schemas/common schemas/specific1/specific1.xsd\[/code\]It generates the classes for \[code\]specific1.xsd\[/code\] in \[code\]mypackage.specific1\[/code\] and the common classes in \[code\]mypackage.commons\[/code\]. But when I try to generate the classes for \[code\]specificN\[/code\], \[code\]xjc\[/code\] throws the following error: \[code\][ERROR] "file:/drive/dir/schemas/common/common1.xsd" is not a part of this compilation. Is this a mistake for "/drive/dir/schemas/common/commonBindings.xjb"? line 2 of file:/drive/dir/schemas/common/commonBindings.xjb\[/code\]I get this error repeated for every common XSD not imported in any specific xsd. Is there any way I can make \[code\]xjc\[/code\] ignore the bindings in \[code\]commonBindings.xjb\[/code\] that aren't used in the XSD I'm generating the classes for?Or, am I aiming in the wrong direction by using this approach, and should be, for instance, using annotations in the specific xsd? I'd like to avoid modifying the schemas if possible.
 
Back
Top