0

我有一个A.xsd导入的架构B.xsd及其复杂元素之一<complex-element>。现在我已经.episode通过编译创建了文件,B.xsd并将其用作A.xsd. 但除了 之外<complex-element>,所有其他子元素类都会重新生成。

a.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://example.com/a" xmlns="http://example.com/a"
    xmlns:tns="http://example.com/b" elementFormDefault="qualified">

    <xs:import namespace="http://example.com/b" schemaLocation="b.xsd" />

    <xs:element name="root">
        <xs:complexType>
            <xs:all>
                <xs:element name="element1" type="xs:string" minOccurs="0" />
                <!-- more elements -->
                <xs:element name="elementx" type="xs:string" />
                <xs:element ref="tns:complex-element" minOccurs="0" />
            </xs:all>
            <xs:attribute name="version" type="xs:string" />
        </xs:complexType>
    </xs:element>

</xs:schema>

B.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://example.com/b" xmlns="http://example.com/b"
    elementFormDefault="qualified">

    <xs:element name="complex-element">
        <xs:complexType>
            <xs:all>
                <xs:element name="list" type="list" minOccurs="0"
                    maxOccurs="1" />
                <xs:element name="code" type="code" minOccurs="0"
                    maxOccurs="1" />
                <xs:element name="message" type="xs:string" minOccurs="0"
                    maxOccurs="1" />
            </xs:all>
        </xs:complexType>
    </xs:element>

    <xs:complexType name="list">
        <xs:sequence>
            <xs:element name="file" type="file" minOccurs="1"
                maxOccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>

    <xs:simpleType name="code">
        <xs:restriction base="xs:string">
            <xs:enumeration value="S1" />
            <xs:enumeration value="S2" />
            <xs:enumeration value="S3" />
        </xs:restriction>
    </xs:simpleType>
<!-- more elements -->
</xs:schema>

pom.xml

<execution>
    <id>aschema</id>
    <phase>generate-sources</phase>
    <goals>
        <goal>generate</goal>
    </goals>
    <configuration>
        <generateDirectory>src/main/java</generateDirectory>
        <schemaIncludes>
            <include>a.xsd</include>
        </schemaIncludes>
        <bindingIncludes>
            <include>a.xjb</include>
        </bindingIncludes>
        <cleanPackageDirectories>false</cleanPackageDirectories>
        <episode>false</episode>
        <args>
            <arg>-b</arg>
            <arg>${basedir}/src/main/resources/b-episode</arg>
            <arg>-Xinheritance</arg>
            <arg>-Xxew</arg>
            <arg>-Xannotate</arg>
        </args>
        <verbose>true</verbose>
    </configuration>
</execution>    

执行后,类ComplexElement被正确引用到现有包,但所有的子元素<list><code>包下生成的类,org.example.com.a而不是引用包内的现有类org.example.com.b

b集

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" if-exists="true"
    version="2.1">
    <bindings xmlns:tns="http://example.com/b"
        if-exists="true" scd="x-schema::tns">
        <schemaBindings map="false">
            <package name="org.example.com.b" />
        </schemaBindings>
        <bindings if-exists="true" scd="tns:complex-element">
            <class ref="org.example.com.b.ComplexElement" />
        </bindings>
        <bindings if-exists="true" scd="~tns:list">
            <class ref="org.example.com.b.List" />
        </bindings>
        <bindings if-exists="true" scd="~tns:file">
            <class ref="org.example.com.b.File" />
        </bindings>
        <!-- and so on ... -->
    </bindings>
4

1 回答 1

1

请遵循有关使用情节的文档。

简而言之,不要将.episode文件用作文件,而是在插件配置中包含模式A.xsd的编译工件:episodes/episode

<dependencies>
    ...
    <dependency>
        <groupId>com.acme.foo</groupId>
        <artifactId>a-schema</artifactId>
        <version>1.0</version>
    </dependency>
    ...
</dependencies>
<build>
    <defaultGoal>test</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <configuration>
                <extension>true</extension>
                <episodes>
                    <episode>
                        <groupId>com.acme.foo</groupId>
                        <artifactId>a-schema</artifactId>
                        <!-- Version is not required if the artifact is
                            configured as dependency -->
                    </episode>
                </episodes>
            </configuration>
        </plugin>
    </plugins>
</build>

所以你不应该-b ${basedir}/src/main/resources/b-episode等等。

免责声明:我是maven-jaxb2-plugin.

于 2016-07-19T20:09:58.030 回答