有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java不能在单个xsd元素上使用jaxb绑定

我正在使用jaxb从xsd文件生成java源代码

我希望能够在每个元素的基础上指定在哪些包中生成源,但是每当我生成源时,就会出现以下错误:

[ERROR] ****/src/main/xjb/common.xjb[8,24]
com.sun.istack.SAXParseException2: compiler was unable to honor this schemaBinding customization. It is attached to a wrong place, or its inconsistent with other bindings.

我的绑定文件是通用的。xjb正在尝试将名为(属性值)“api”的元素放置在包“com”中。myxml。常见的api':

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

    <jxb:bindings schemaLocation="../xsd/common/common.xsd" node="/xs:schema">

        <jxb:bindings node="//xs:element[@name='api']">
            <jxb:schemaBindings>
                <jxb:package name="com.myxml.common.api" />
            </jxb:schemaBindings>
        </jxb:bindings>

    </jxb:bindings>

</jxb:bindings>

我的xsd文件很常见。xsd是:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.1" xml:lang="en">

    <xs:element name='api'>
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string" />
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>

</xs:schema>

我正在使用以下Maven插件来让一切顺利进行:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>1.5</version>

    <executions>
        <execution>
            <id>schema00-generate</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>xjc</goal>
            </goals>
            <configuration>
                <schemaFiles>common/common.xsd</schemaFiles>
                <bindingFiles>common.xjb</bindingFiles>
                <bindingDirectory>${project.basedir}/src/main/xjb</bindingDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

为什么我会出现这个错误,我该如何解决它?据我所知,在这个阶段,我没有使用任何其他绑定


共 (1) 个答案

  1. # 1 楼答案

    同一命名空间中的元素不能映射到不同的包,因此不能为顶层以外的任何内容定义包