XJC – 编译器无法遵守此类自定义

我想从我的Java项目调用ISAN Restful API,所以我试图使用maven-jaxb2-plugin从xsd文件生成java bean。 这是xsds:

  • http://www.isan.org/schema/v1.11/common/common.xsd
  • http://www.isan.org/schema/v1.21/common/serial.xsd
  • http://www.isan.org/schema/v1.11/common/version.xsd
  • http://www.isan.org/ISAN/isan.xsd
  • http://www.isan.org/schema/v1.11/common/title.xsd
  • http://www.isan.org/schema/v1.11/common/externalid.xsd
  • http://www.isan.org/schema/v1.11/common/participant.xsd
  • http://www.isan.org/schema/v1.11/common/language.xsd
  • http://www.isan.org/schema/v1.11/common/country.xsd

我下载了这些文件并将它们复制到我的src / main / resources文件夹中并定义了一个目录。 当我构建项目时,我收到一个错误,因为两个类型具有相同的名称:

org.xml.sax.SAXParseExceptionpublicId: http://www.isan.org/schema/v1.11/common/language; systemId: http://www.isan.org/schema/v1.11/common/language.xsd; lineNumber: 39; columnNumber: 48; A class/interface with the same name "org.isan.CodingSystemType" is already in use. Use a class customization to resolve this conflict. org.xml.sax.SAXParseExceptionpublicId: http://www.isan.org/schema/v1.11/common/country; systemId: http://www.isan.org/schema/v1.11/common/country.xsd; lineNumber: 39; columnNumber: 48; (Relevant to above error) another "CodingSystemType" is generated from here. 

这是正确的:language.xsd和country.xsd都定义了一个名为CodingSystemType的类型:

             

正如所建议的那样,我尝试对country.xsd类型使用类自定义。 我在pom.xml中添加了这个绑定:

   http://www.isan.org/schema/v1.11/common/country.xjb   

xjc文件:

        

现在,我得到另一个我无法处理的错误:

 [ERROR] Error while parsing schema(s).Location [ http://www.isan.org/schema/v1.11/common/country.xjb{7,58}]. com.sun.istack.SAXParseException2; systemId: http://www.isan.org/schema/v1.11/common/country.xjb; lineNumber: 7; columnNumber: 58; compiler was unable to honor this class customization. It is attached to a wrong place, or its inconsistent with other bindings. [ERROR] Error while parsing schema(s).Location [ http://www.isan.org/schema/v1.11/common/country.xsd{39,48}]. com.sun.istack.SAXParseException2; systemId: http://www.isan.org/schema/v1.11/common/country.xsd; lineNumber: 39; columnNumber: 48; (the above customization is attached to the following location in the schema) 

我将添加另一个答案,因为它涉及有关您的架构编译的不同主题。

我还注意到这两个简单类型实际上属于不同的命名空间。 所以它们实际上不应该首先在同一个包中生成。

我想你只需使用generatePackageorg.isan指定为目标包。 因此,所有命名空间最终都在一个包中,这非常糟糕。 如果每个命名空间有一个包,则JAXB最有效。 如果你不这样做会很奇怪。

所以我一般不鼓励使用generatePackage ,而是使用jaxb:package代替:

       

我还建议使用主要/次要架构版本的包名称。 您可能需要稍后并行支持多个模式版本。

尝试

    

代替。

我认为XJC在自定义枚举和普通类之间有所不同。 查看相关问题:

  • JAXB:作为枚举的匿名简单类型?