3

我正在使用 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.

我的绑定文件 common.xjb 试图将名称(属性值)'api'的元素放在包'com.myxml.common.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 文件 common.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>

为什么我会收到此错误,我该如何解决?我知道在这个阶段我没有使用任何其他绑定。

4

1 回答 1

3

来自同一命名空间的元素不能映射到不同的包,因此不能为顶层以外的任何东西定义包

于 2012-11-24T15:18:14.133 回答