Generating jaxb classes with naming conflicts

我只是一个虾纸丫 提交于 2020-01-05 08:30:36

问题


I have created a new JAXB project and imported an xsd which I am trying to generate JAXB classes off of. When I select "Generate->JAXB Classes" I get a number of similar errors all which relate to naming conflicts:

 A class/interface with the same name "generated.Document" is already in use. Use a class customization to resolve this conflict.

The above error is thrown from the following piece of the .xsd file

 <xs:complexType name="Document">
    <xs:sequence>
      <xs:element ref="Document"/>
    </xs:sequence>
 </xs:complexType>
 <xs:element name="Document">
 ...

Changing the .xsd file is not an option for me so I have to find another way. I have been reading about the possibility of creating a bindings file. I can't seem to find good documentation on how to do that for my particular problem. My three main questions are:

  • Should I create a new bindings .xjb file and add it to eclipse to solve this issue?
  • How should this bindings file look in order to resolve the "Document" naming conflicts?
  • How do I get eclipse to recognize the bindings file when I run "Generate -> JAXB Classes

回答1:


  • Should I create a new bindings .xjb file and add it to eclipse to solve this issue?

yes, you can with an xjb file

  • How should this bindings file look in order to resolve the "Document" naming conflicts?

(e.g. I don't know your entire xsd, this is only an example)

<bindings version="2.0" xmlns="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    xmlns:annox="http://annox.dev.java.net">

        <bindings node="xs:complexType[@name='Document']">
            <class name="Item"/>
        </bindings>

</bindings>
  • How do I get eclipse to recognize the bindings file when I run "Generate -> JAXB Classes

Eclipse allows you to attach an XJB file (Binding files:)

I hope I've given you all the answers about your question.



来源:https://stackoverflow.com/questions/24806716/generating-jaxb-classes-with-naming-conflicts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!