を使用して、いくつかの特定の XSD から Java クラスを生成しようとしていxjc
ます。これらのスキーマにはいくつかの共通の定義があるため、多数の共通 XSD をインポートします。特に、ゼロからすべての一般的な XSD を含めることができます。
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:
<jxb:bindings schemaLocation="common1.xsd" node="/xsd:schema">
<jxb:schemaBindings>
<jxb:package name="mypackage.commonclasses"/>
</jxb:schemaBindings>
</jxb:bindings>
I've got the following structure:
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
It all works fine with:
xjc -b schemas/specific1
-b schemas/common
schemas/specific1/specific1.xsd
It generates the classes for specific1.xsd
in mypackage.specific1
and the common classes in mypackage.commons
. But when I try to generate the classes for specificN
, xjc
throws the following error:
[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
I get this error repeated for every common XSD not imported in any specific xsd.
Is there any way I can make xjc
ignore the bindings in commonBindings.xjb
that aren't used in the XSD I'm generating the classes for?
または、このアプローチを使用して間違った方向を目指していますか?たとえば、特定の xsd で注釈を使用する必要がありますか? 可能であれば、スキーマの変更は避けたいと思います。