I use the jibx Maven plugin to convert some xsds to Java source codes. In a schema A, there is a reference to a type defined in a schema B. Before, I used this pom.xml configuration and everything worked fine:
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.3</version>
<configuration>
<schemaLocation>${basedir}/resources/oxm/schemas</schemaLocation>
<schemaBindingDirectory>${basedir}/src/java</schemaBindingDirectory>
<includeSchemas>
<includeSchema>schemaA.xsd</includeSchema>
<includeSchema>schemaB.xsd</includeSchema>
<includeSchema>schemaC.xsd</includeSchema>
</includeSchemas>
<verbose>true</verbose>
</configuration>
</plugin>
The input schema A is something like:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="myApp.com/schema/schemaA"targetNamespace="http://myApp.com/schema/schemaA" xmlns:rsType="http://myApp.com/schema/schemaB">
<xs:import schemaLocation="schemaB.xsd" namespace="http://myApp.com/schema/schemaB" />
<xs:complexType name="classAType">
<xs:sequence>
<xs:element name="objB" type="rsType:classBType" />
</xs:sequence>
<xs:attribute name="foo" type="xs:int" />
</xs:complexType>
Input schema B has similar code with definition of classBType.
The former Java source output was something like:
class classA
{
classB objB;
int foo;
}
Recently, I separated the conversion of schemas in different build executions in the pom.xml to be able to define different target package for them. My new pom.xml is:
<plugin>
<groupId>org.jibx</groupId>
<artifactId>jibx-maven-plugin</artifactId>
<version>1.2.3</version>
<configuration>
<schemaLocation>${basedir}/resources/oxm/schemas</schemaLocation>
<schemaBindingDirectory>${basedir}/src/java</schemaBindingDirectory>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<id>schemaCodegenA</id>
<goals>
<goal>schema-codegen</goal>
</goals>
<configuration>
<includeSchemas>
<includeSchema>schemaA.xsd</includeSchema>
</includeSchemas>
<options>
<package>com.myApp.jibxgenerated.schema.resource</package>
</options>
</configuration>
</execution>
(... one execution for each set of schemas)
The Java source output now is:
class classA
{
// all properties of class B here
int classBattrib1;
int classBattrib2;
int classBattribN;
int foo;
}
Is this the expected behavior? I want to have the classB reference back in the class A source code, is there any way to achieve this?
Thanks in advance for any help.
user1550682,
Actually JiBX handles this case pretty easily. You can package each schema in a separate jar and easily reference a sub-module using the maven plugin.
Take a look at the instructions for modular schema here: http://jibx.sourceforge.net/maven-jibx-plugin/modular-codegen.html
and take a look at the example code in github here: https://github.com/jibx/maven-plugin/tree/master/test-suite/base-binding-test
This example uses three simple schema: company -> address -> person. and had a simple test that marshalls and unmarshalls some xml.
I hope this helps!
Don