我有一个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>