我有一个架构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>
答案 0 :(得分:1)
请按照using episodes上的文档进行操作。
简而言之,不是将.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
的作者。