web-services – 请帮助:xjc抛出“两个声明导致ObjectFactory类中的冲突”

前端之家收集整理的这篇文章主要介绍了web-services – 请帮助:xjc抛出“两个声明导致ObjectFactory类中的冲突”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
通过简化的XSD进行以下操作:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xs:schema targetNamespace="com.acme" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  3. <xs:element name="Widget">
  4. <xs:complexType>
  5. <xs:sequence>
  6. <xs:element
  7. minOccurs="0" name="color" nillable="true" type="xs:string" />
  8. </xs:sequence>
  9. </xs:complexType>
  10. </xs:element>
  11. <xs:element name="WidgetColor" type="xs:string" />
  12. </xs:schema>

然后,尝试以下操作:

  1. xjc test.xsd

您应该总是得到以下异常:

  1. parsing a schema...
  2. compiling a schema...
  3. [ERROR] Two declarations cause a collision in the ObjectFactory class.
  4. line 11 of file:/C:/test.xsd
  5.  
  6. [ERROR] (Related to above error) This is the other declaration.
  7. line 7 of file:/C:/test.xsd
  8.  
  9. Failed to produce code.

请注意,元素名称“Widget”是complexType,并且具有名为“color”的元素.在元素“Widget”的同一级别,还有一个名为“WidgetColor”的简单元素.

更令人费解的是,如果删除属性minOccurs =“0”或者从“color”元素序列中删除属性nillable =“true”,则xjc会成功编译模式.

有没有人见过这个问题或者可以建议一个解决方案?

谢谢,

麦克风.

解决方法

好吧,我终于想出了如何解决我的问题.它在于使用自定义绑定为其中一个声明指定不同的类名.

custom-binding.xjb的内容

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <bindings version="2.0" xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  3. <bindings schemaLocation="test.xsd">
  4. <bindings node="//xs:element[@name='WidgetColor']">
  5. <class name="BaseWidgetColor" />
  6. </bindings>
  7. </bindings>
  8. </bindings>

操作:

  1. C:\>xjc -b custom-binding.xjb test.xsd
  2. parsing a schema...
  3. compiling a schema...
  4. acme\com\BaseWidgetColor.java
  5. acme\com\ObjectFactory.java
  6. acme\com\Widget.java
  7. acme\com\package-info.java

Patience et longueur de temps valent mieux que rage et acharnement ……!

猜你在找的HTML相关文章