我試圖從幾個特定的XSD中用xjc
生成Java類。這些模式有一些共同的定義,因此它們導入了許多常見的XSD。特別是,它們可以包含從零到所有常見的XSD。使用xjc和綁定定義常見XSD的包名稱
我想將特定XSD中的所有類生成爲特定的包,但將生成的普通模式的類保留在公共包中,這樣它們就不會針對源樹中的每個特定模式重複。
我已經瞭解到,自定義綁定可以用來在每個模式的基礎上指定封裝,例如:
<jxb:bindings schemaLocation="common1.xsd" node="/xsd:schema">
<jxb:schemaBindings>
<jxb:package name="mypackage.commonclasses"/>
</jxb:schemaBindings>
</jxb:bindings>
我有以下結構:
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
它可以正常工作:
xjc -b schemas/specific1
-b schemas/common
schemas/specific1/specific1.xsd
它生成中的specific1.xsd
的類和mypackage.commons
中的常見類。但是,當我嘗試生成的類specificN
,xjc
引發以下錯誤:
[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
我得到這個錯誤重複在任何特定的XSD不導入每個公共XSD。
有沒有什麼辦法可以讓xjc
忽略在commonBindings.xjb
中沒有在XSD中使用的綁定我正在爲類生成類?
或者,我是否使用這種方法瞄準了錯誤的方向,應該是,例如,在特定的xsd中使用註釋?如果可能的話,我想避免修改模式。