【问题标题】:Create Java classes with JaxB使用 JaxB 创建 Java 类
【发布时间】:2012-10-08 09:39:58
【问题描述】:

我尝试通过此 XSD http://pda.rosreestr.ru/upload/www/files/02_V04_STD_Region_Cadastr_KV.rar 使用 JaXB 创建 Java 类,但遇到了这些错误。

parsing a schema...
[WARNING] Simple type "dAllDocuments" was not mapped to Enum due to EnumMemberSizeCap limit. Facets count: 298, current limit: 256. You can use customization attribute "typesafeEnumMaxMembers" to extend the limit.
line 3 of file:/D:/liferay-develop/workspace/JABX_test/src/02_V04_STD_Region_Cadastr_KV/dAllDocuments.xsd

compiling a schema...
[ERROR] Two declarations cause a collision in the ObjectFactory class.
line 1645 of file:/D:/liferay-develop/workspace/JABX_test/src/02_V04_STD_Region_Cadastr_KV/STD_Region_Cadastr_KV.xsd

[ERROR] (Related to above error) This is the other declaration.   
line 1587 of file:/D:/liferay-develop/workspace/JABX_test/src/02_V04_STD_Region_Cadastr_KV/STD_Region_Cadastr_KV.xsd

Failed to produce code.

当我使用其他模式时,一切都很好。我不擅长使用 XML,您能告诉我这些错误是什么意思以及如何解决吗?

更新

我尝试在类生成中使用 binding.xml,但出现此错误。

C:\Documents and Settings\kliver\Мои документы\Загрузки\jaxb-ri-2.2.6\bin>xjc -d
out -b binding.xml D:/liferay-develop/workspace/JABX_test/src/02_V04_STD_Region
_Cadastr_KV/STD_Region_Cadastr_KV.xsd
parsing a schema...
[ERROR] "D:/liferay-develop/workspace/JABX_test/src/02_V04_STD_Region_Cadastr_KV
/STD_Region_Cadastr_KV.xsd" is not a part of this compilation. Is this a mistake
 for "file:/D:/liferay-develop/workspace/JABX_test/src/02_V04_STD_Region_Cadastr
_KV/STD_Region_Cadastr_KV.xsd"?
 line 6 of file:/C:/Documents%20and%20Settings/kliver/%D0%9C%D0%BE%D0%B8%20%D0%
B4%D0%BE%D0%BA%D1%83%D0%BC%D0%B5%D0%BD%D1%82%D1%8B/%D0%97%D0%B0%D0%B3%D1%80%D1%8
3%D0%B7%D0%BA%D0%B8/jaxb-ri-2.2.6/bin/binding.xml

[WARNING] Simple type "dAllDocuments" was not mapped to Enum due to EnumMemberSi
zeCap limit. Facets count: 298, current limit: 256. You can use customization at
tribute "typesafeEnumMaxMembers" to extend the limit.
 line 3 of file:/D:/liferay-develop/workspace/JABX_test/src/02_V04_STD_Region_C
adastr_KV/dAllDocuments.xsd

Failed to parse a schema.

更新2

我试试这个绑定:

<jxb:bindings 
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">

    <!-- Raise theEnumMemberSizeCap limit -->
    <jxb:bindings >
       <jxb:globalBindings typesafeEnumMaxMembers="2000"/>
   </jxb:bindings>

   <jxb:bindings schemaLocation="D:\liferay-develop\workspace\JABX_test\src\02_V04_STD_Region_Cadastr_KV\STD_Region_Cadastr_KV.xsd">
       <jxb:bindings node="//xs:complexType[@name='tRight_Owner']">
           <jxb:class name="tRight_Owner2"/>
       </jxb:bindings>
   </jxb:bindings>

</jxb:bindings>

还有这个控制台命令:

C:\Documents and Settings\kliver\Мои документы\Загрузки\jaxb-ri-2.2.6\bin>xjc -d
out -b binding.xml D:\liferay-develop\workspace\JABX_test\src\02_V04_STD_Region
_Cadastr_KV\STD_Region_Cadastr_KV.xsd

【问题讨论】:

  • 那么,在该文件的第 1587 行和第 1645 行声明了哪些类型?它们似乎会创建冲突的类名,您要么需要统一它们(如果它们确实代表相同的东西),要么自定义这些类型的名称。
  • 在第 1645 行 &lt;xs:complexType name="tRight_Owner"&gt;。那么我如何理解它对tRight_Owner 类型的定义。但我没有看到其他具有此名称的类型。

标签: java xsd jaxb


【解决方案1】:

您可以使用外部绑定文件为其中一种复杂类型指定不同的类名。

binding.xml

<jxb:bindings 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    version="2.1">

   <!-- Raise theEnumMemberSizeCap limit -->
   <jxb:bindings >
       <jxb:globalBindings typesafeEnumMaxMembers="2000"/>
   </jxb:bindings>

    <jxb:bindings schemaLocation="your-schema.xsd">
            <jxb:bindings node="//xs:complexType[@name='tRight_Owner']">
                <jxb:class name="TRight_Owner2"/>
            </jxb:bindings>
    </jxb:bindings>

</jxb:bindings>

xjc 命令行是:

xjc -d out -b binding.xml your-schema.xsd

【讨论】:

  • 我尝试了您的代码,但出现错误。请查看问题的更新。
  • @KliverMax - 我更新了我的答案以解决 EnumMemberSizeCap 限制。您可以发布您尝试使用的绑定文件吗?
  • 它的作品。我在架构路径上失败了。当我将架构放到 xjs 位置时,它会为我生成类/
  • 如果你使用的是 maven-jaxb2-plugin,这个例子会很有帮助:github.com/highsource/maven-jaxb2-plugin/tree/master/tests/res
【解决方案2】:

对于那些后来遇到这个问题的人来说,这种方法对我有用。

环境:Netbeans 7.4

构建方法:Maven - jaxb2-maven-plugin

  1. src\main 中创建一个名为xjb 的文件夹。
  2. 在该文件夹中创建一个名为 binding.xjb(或任何其他 .xjb 名称)的文件。

在里面:

<jxb:bindings 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    version="2.1">

   <!-- Raise theEnumMemberSizeCap limit -->
   <jxb:bindings >
       <jxb:globalBindings typesafeEnumMaxMembers="2000"/>
   </jxb:bindings>

</jxb:bindings>

请注意,这不是 Blaise 帖子的替代解决方案。

【讨论】:

    【解决方案3】:

    我使用的是 0.13.0 版的 maven-jaxb2-plugin,我发现绑定文件的正确路径是:

    src/main/resources/binding.xjb
    

    内容与OldCurmudgeon提出的相同,即:

    <jxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="2.1">
    
        <!-- Raise theEnumMemberSizeCap limit -->
        <jxb:bindings>
            <jxb:globalBindings typesafeEnumMaxMembers="2000" />
        </jxb:bindings>
    
    </jxb:bindings>
    

    【讨论】:

      【解决方案4】:

      您的 XSD 有问题,有多个同名声明 tRight_Owner
      第 1587 行:

       <xs:complexType>
                              <xs:complexContent>
                                  <xs:extension base="tRight_Owner"/>
                              </xs:complexContent>
                          </xs:complexType>
      

      第 1645 行:

      <xs:complexType name="tRight_Owner">
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多