【问题标题】:Jaxb binding file being ignoredJaxb 绑定文件被忽略
【发布时间】:2011-12-12 02:43:48
【问题描述】:

我在为一组模式构建 JAXB 绑定时遇到了一些麻烦,这让我有点烦躁。这是有问题的架构(它只是这个特定版本中可能的架构之一):

<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xml="http://www.w3.org/XML/1998/namespace" targetNamespace="http://www.w3.org/XML/1998/namespace">
<attribute name="lang" type="language">
    <annotation>
        <documentation>In due course, we should install the relevant ISO 2- and 3-letter
            codes as the enumerated possible values . . .</documentation>
    </annotation>
</attribute>
<attribute name="space" default="preserve">
    <simpleType>
        <restriction base="NCName">
            <enumeration value="default"/>
            <enumeration value="preserve"/>
        </restriction>
    </simpleType>
</attribute>
<attributeGroup name="specialAttrs">
    <attribute ref="xml:lang"/>
    <attribute ref="xml:space"/>
</attributeGroup>

xjc 声称上面声明的属性已经在其他地方声明:

parsing a schema...
[ERROR] 'lang' is already defined
  line 26 of file:../../gml/3.1.1/smil/xml-mod.xsd

[ERROR] (related to above error) the first definition appears here
  line 88 of http://www.w3.org/2001/03/xml.xsd

[ERROR] 'space' is already defined
  line 34 of file:../../gml/3.1.1/smil/xml-mod.xsd

[ERROR] (related to above error) the first definition appears here
  line 95 of http://www.w3.org/2001/03/xml.xsd

[ERROR] 'specialAttrs' is already defined
  line 39 of file:../../gml/3.1.1/smil/xml-mod.xsd

[ERROR] (related to above error) the first definition appears here
  line 111 of http://www.w3.org/2001/03/xml.xsd

Failed to parse a schema.

做一些研究会让我相信问题是我需要一个绑定文件来解决重复的属性....我有一个:

<jaxb:bindings version="1.0" xmlns:jaxb="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" jaxb:extensionBindingPrefixes="xjc">

<jaxb:bindings schemaLocation="../../gml/3.1.1/smil/xml-mod.xsd" node="/xs:schema">
    <jaxb:bindings node="//xs:attribute[@name='lang']">
        <jaxb:property name="langAttribute"/>
    </jaxb:bindings>
    <jaxb:bindings node="//xs:attribute[@name='space']">
        <jaxb:property name="spaceAttribute"/>
    </jaxb:bindings>
    <jaxb:bindings node="//xs:attributeGroup[@name='specialAttrs']">
        <jaxb:property name="specialAttrsAttribute"/>
    </jaxb:bindings>
</jaxb:bindings>

但问题仍然存在。带有或不带有绑定文件的错误消息是相同的。我知道该文件正在被使用,因为如果我弄乱了节点选择器的 xpath,我会收到一条错误消息。就像 xjc 知道绑定文件在那里但忽略它。

以下是无法构建绑定的命令行:

C:\tools\jaxb-ri-20110512\bin\xjc -episode ..\..\..\common.ogc -d ..\..\..\src -p com.ogc.bindings -b ..\..\..\bindings.xsd -catalog ..\..\..\ogc.cat -extension  sosAll.xsd

我在 jdk6 本机 jaxb (2.0) 和 jaxb 2.2.4 上都试过这个(我将 jaxb-api.jar 安装在背书目录中)

【问题讨论】:

    标签: binding jaxb xjc


    【解决方案1】:

    我认为这是命名空间冲突的问题,您没有为架构元素定义命名空间,而且您似乎使用的属性名称与 xml 架构 (xml.xsd) 中定义的属性冲突

    【讨论】:

      【解决方案2】:

      当您尝试编译 OGC 模式时,您可能会发现 this project 很有帮助。它包含已编译的 SOS 架构。

      【讨论】:

      【解决方案3】:

      XJC(与 JDK 捆绑),如果绑定文件的路径或 XSD/WSDL 太长,则忽略绑定文件。

      如果绑定文件的路径太长,在 Oracle 64 位 JDK 1.6.0.45、Windows 7 终极版和 Linux、XJC(与 JDK 捆绑)上观察并确认的问题会忽略绑定文件。

      我没有时间对此问题进行详细研究;我通过简单地缩短 svn 结帐路径解决了我的问题。这是最奇怪的问题——我无法在我的 Windows 8 笔记本电脑和 Linux 上重现该问题,但在 Windows 7 工作站上,构建一直失败。我通过确认其他路径确定了这个问题,在构建工作的 Windows 8 LAPTOP 与路径有点长(6 个字符 -> /trunk)的 Windows 7 Ultimate 之间没有区别。

      无需任何代码、配置、xml 架构或绑定文件更改即可解决问题。在这里发帖,以便其他可能遇到此问题的人比我更轻松。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-05-02
        • 2017-03-17
        • 2018-06-09
        • 1970-01-01
        • 2011-09-28
        • 1970-01-01
        • 2013-11-15
        • 1970-01-01
        相关资源
        最近更新 更多