xjc:两个声明在ObjectFactory类中导致冲突
运行以下xjc命令会引发错误:
$ xjc "ftp://ftp.ncbi.nih.gov/bioproject/Schema/Core.xsd" parsing a schema... compiling a schema... [ERROR] Two declarations cause a collision in the ObjectFactory class. line 340 of ftp://ftp.ncbi.nih.gov/bioproject/Schema/Core.xsd [ERROR] (Related to above error) This is the other declaration. line 475 of ftp://ftp.ncbi.nih.gov/bioproject/Schema/Core.xsd
虽然我理解JAXB绑定以及XJC中存在什么冲突,但我不明白当前模式中的冲突在哪里。
我应该怎么解决这个问题?
谢谢,
皮埃尔
更新:这里是错误的上下文:
$ curl -s "ftp://ftp.ncbi.nih.gov/bioproject/Schema/Core.xsd" | sed 's/^[ \t]*//' | cat -n | egrep -w -A 10 -B 10 '(340|475)' 330 332 333 334 Optionally provide description especially when "eOther" is selected 335 336 337 338 Identifier of the BioSample when known 339 340 341 342 343 344 345 346 347 348 The scope and purity of the biological sample used for the study 349 350 -- 465 Please, fill Description element when choose "eOther" 466 467 468 469 470 471 472 473 474 Set of Targets references to BioSamples 475 476 477 478 479 480 481 482 483 484 485 The core experimental approach used to obtain the data that is submitted to archival databases
我将引用网上JAXB最官方的非官方指南 。
当模式包含类似的外观元素/类型名称时,它们可能导致“两个声明导致ObjectFactory类中的冲突”错误。 更确切地说,对于所有类型和许多元素中的每一个(确切地说是哪些元素获得工厂以及什么不是有点难以解释),XJC在同一个包中的ObjectFactory类上生成一个方法。 为XJC生成一些文件的每个包创建ObjectFactory类。 方法的名称源自XML元素/类型名称,如果两个元素/类型尝试生成相同的方法名称,则报告错误。
也就是说,你有两种选择。
第一种是定义这样的外部绑定XML
在生成的ObjectFactory
类中,这将创建两个名为createTypeBioSampleSet
和createTypeTargetBioSampleSet
方法(JAXB将您指定的名称附加到单词create
),该方法可用于生成BioSampleSet
和TargetBioSampleSet
对象。
(没有必要为两种类型定义绑定。)
我不确定为什么JAXB拒绝从给定模式生成类,但是当我只指定一个绑定(例如BioSampleSet
)时,另一个类型的工厂方法被命名为createTypeProjectProjectTypeSubmissionWhateverThisAndThatTargetTargetSampleBioCatDogWoofTypeIDoNotKnowWhatElse
所以我认为JAXB在这个长方法标识符上被阻塞,因为它以某种方式设法为这两种类型创建相同的。 我认为这是JAXB中的一些实现细节。
另一个解决方案是为BioSampleSet
创建一个基本类型,并在这两个位置使用它
... ... ... ... ... ...
最好的解决方案是从模式中删除每个匿名类型声明。 如果你能做到这一点,那就去做吧,因为这个架构看起来像一团糟(至少对我来说)。