无法使用绑定从xsd生成java类

时间:2015-06-25 08:56:11

标签: java xml binding xsd

我在路径中有很多XSD来生成java类。在我的绑定文件中,我有:

<jaxb:bindings schemaLocation="../aiseo/xsd/AiseoTypy.xsd" node="/xs:schema">

</jaxb:bindings>

但它会引发错误:

[ERROR] Failed to execute goal org.apache.cxf:cxf-codegen-plugin:3.1.1:wsdl2java (generate-sources-iszr) on project iszr-dataset: Execution generate-sources-iszr of goal org.apache.cxf:cxf-codegen-plugin:3.1.1:wsdl2java failed: file:/some/path/resources/wsdl/binding/bindings.xml [16,79]: "file:/some/path/resources/wsdl/aiseo/xsd/AiseoTypy.xsd" is not a part of this compilation. Is this a mistake for "file:/some/path/resources/wsdl/ais3/xsd/Ais3Typy.xsd"?

所以我试着改变它的建议

<jaxb:bindings schemaLocation="../ais3/xsd/Ais3Typy.xsd" node="/xs:schema">

</jaxb:bindings>    

但它会抛出错误并建议我使用以前的XSD。

[ERROR] Failed to execute goal org.apache.cxf:cxf-codegen-plugin:3.1.1:wsdl2java (generate-sources-iszr) on project iszr-dataset: Execution generate-sources-iszr of goal org.apache.cxf:cxf-codegen-    plugin:3.1.1:wsdl2java failed: file:/some/path/resources/wsdl/binding/bindings.xml [15,77]: "file:/some/path/resources/wsdl/ais3/xsd/Ais3Typy.xsd" is not a part of this compilation. Is this a mistake for "file:/some/path/resources/wsdl/aiseo/xsd/AiseoTypy.xsd"?

所以我真的很困惑,为什么它仍会在两种情况下抛出错误

两个XSD都应该在路径中,因为你可以看到它建议我。

更新:

调试后我发现问题出在哪里。在第一种情况下,它在开始处理wsdl Ais3 ...

时生成了一些类并抛出错误

行:

[DEBUG] Calling wsdl2java with args: [-encoding, UTF-8, -d, /home/hudect/git/ais3/backend/common-reactor/iszr-dataset/target/generated-sources/cxf, -b, file:/some/path/resources/wsdl/binding/bindings.xml, -xjc-Xinheritance, -verbose, file:/some/path/resources/wsdl/aiseo/wsdl/AiseoCtiAifo.wsdl]
Loading FrontEnd jaxws ...
Loading DataBinding jaxb ...
wsdl2java -encoding UTF-8 -d /some/path/generated-sources/cxf -b file:/home/some/path/resources/wsdl/binding/bindings.xml -xjc-Xinheritance -verbose file:/some/path/resources/wsdl/aiseo/wsdl/AiseoCtiAifo.wsdl
wsdl2java - Apache CXF 3.1.1

错误:

[DEBUG] Calling wsdl2java with args: [-encoding, UTF-8, -d, /some/path/generated-sources/cxf, -b, file:/some/path/resources/wsdl/binding/bindings.xml, -xjc-Xinheritance, -verbose, file:/some/path/resources/wsdl/ais3/wsdl/Ais3RrcCtiHromadneAifo.wsdl]
Loading FrontEnd jaxws ...
Loading DataBinding jaxb ...
wsdl2java -encoding UTF-8 -d /some/path/generated-sources/cxf -b file:/some/path/resources/wsdl/binding/bindings.xml -xjc-Xinheritance -verbose file:/some/path/resources/wsdl/ais3/wsdl/Ais3RrcCtiHromadneAifo.wsdl
wsdl2java - Apache CXF 3.1.1

但我不明白为什么它必须在路上?在XSD中,ais3使用Ais3Typy,在aiseo中使用aiseoTypy。是否有选项如何只使用一个绑定文件,其中所有这些声明都写入。我知道我可以把它分成更多的文件并在maven中创建更多的执行但是我有10个以上的文件* Typy.xsd所以我只想要一个绑定。

1 个答案:

答案 0 :(得分:0)

schemaLocation的路径不正确。

它应该与您的绑定文件相关。

如果您有类似

的内容
workspace/
  -  binding/xyz.xjb
  -  xsd/file.xsd

你应该:

schemaLocation="../xsd/file.xsd"