I have a schema A.xsd
that imports B.xsd
and its one of the complex element <complex-element>
. Now I have created the .episode
file from compiling the B.xsd
and used as input to A.xsd
. But except for the <complex-element>
, all other child elements classes are regenerated again.
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>
After execution, the Class ComplexElement
gets correctly referenced to existing package, but all of the child elements <list>
and <code>
generates class under the package of org.example.com.a
instead to refer existing classes inside org.example.com.b
package.
b-episode
<?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>
Please follow the documentation on using episodes.
In short, instead of using the
.episode
file as a file, include the compiled artifact of the schemaA.xsd
as anepisodes/episode
in the plugin configuration:So you shouldn't
-b ${basedir}/src/main/resources/b-episode
etc.Disclaimer: I'm the author of
maven-jaxb2-plugin
.