问题描述
我创建了一个新的JAXB项目并导入了一个xsd,我试图从中生成JAXB类。当我选择Generate-> JAXB Classes时,我得到了许多与命名冲突有关的类似错误:
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.
从.xsd文件的以下部分抛出上述错误
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">
...
更改.xsd文件对我来说不是一个选项所以我有找到另一种方式。我一直在阅读有关创建绑定文件的可能性。我似乎无法找到关于如何为我的特定问题做到这一点的好文档。我的三个主要问题是:
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:
- 我应该创建一个新的绑定.xjb文件并将其添加到eclipse来解决这个问题吗?
- 为解决文档命名冲突,此绑定文件应如何显示?
- 当我运行生成 - > JAXB类
推荐答案
- 我应该创建一个新的绑定.xjb文件并将其添加到eclipse中以解决此问题吗?
- 此绑定文件应如何按顺序显示解决文档命名冲突?
是的,您可以使用xjb文件
yes, you can with an xjb file
(例如我不知道你的整个xsd,这只是一个例子)
(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>
- 当我运行Generate - > JAXB Classes
时,如何让eclipse识别绑定文件? Eclipse允许您附加XJB文件(绑定文件:)
Eclipse allows you to attach an XJB file (Binding files:)
我希望我已经给你关于你问题的所有答案。
I hope I've given you all the answers about your question.
这篇关于生成具有命名冲突的jaxb类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!