I want to have a project A with some common used XML schema files and some java classes dependent on the generated classes (generated from jaxb), using namespace a and package a, and I want to have a project B dependent on project A.
in project B i want to have a XML schema file using some XML types from project A, project b has namespace b, then JAXB needs to generate java classes from schema b into the package b.
I know that episodes and catalogs might help, but i can not prevent jaxb to create the java classes comming from schema a twice in project b.
here is my maven configuration:
project A:
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<schemaIncludes>
<include>wsdl/WebServiceBaseRequestResponse.xsd</include>
</schemaIncludes>
<generatePackage>a</generatePackage>
<episode>true</episode>
</configuration>
</plugin>
</plugins>
</build>
Project B :
<!-- Used to pull XSD files from the JAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-xsd-files</id>
<phase>initialize</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>a</groupId>
<artifactId>a-xsd</artifactId>
<version>${project.version}</version>
<type>jar</type>
</artifactItem>
</artifactItems>
<includes>wsdl/*.xsd</includes>
<outputDirectory>${project.basedir}/target/xsd-includes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<extension>true</extension>
<episodes>
<episode>
<groupId>a</groupId>
<artifactId>sca-xsd</artifactId>
<version>${project.version}</version>
</episode>
</episodes>
<episode>false</episode>
<schemaIncludes>
<include>wsdl/b.xsd</include>
</schemaIncludes>
<generatePackage>b</generatePackage>
</configuration>
</plugin>
b.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema version="1" targetNamespace="a"
xmlns:tns="a" xmlns:com="b"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="a" schemaLocation="..relPathTo/target/xsd-includes/a.xsd>
<xs:element name="addShipmentOrderResult">
<xs:annotation>
<xs:documentation>
Result object for addShipmentOrder.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:complexContent>
<xs:extension base="com:baseResult">
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>
In this way you're not using the episodes, because you unpack the xsd within B project, so regenerates the classes from A project.
You should using the following configuration
Remember to add as dependency the project A.