Domanda

I'm using jaxb to generate java source code from an xsd file.

I want to be able to specify which packages the sources are generated in on a per element basis, however whenever I generate sources I get the following error:

[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.

My bindings file common.xjb is attempting to place the element with the name (attribute value) 'api' in the package '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>

My xsd file common.xsd is:

<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>

And I'm using the following Maven plugin to get everything going:

<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>

Why am I getting this error and how can I resolve it? I don't have any other bindings in use at this stage that I'm aware of.

È stato utile?

Soluzione

Elements from the same namespace cannot be mapped to different packages so the package cannot be defined for anything other than the top level

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top