How do I generate multiple .xsd's into the same ObjectFactory?

4.2k views Asked by At

I need an ObjectFactory with multiple java objects from multiple schemas. I have had 0 luck with several different plugins and variations of those plugins. Currently I am using the following :

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-xjc-plugin</artifactId>
    <version>2.6.2</version>
    <configuration>
        <extensions>
            <extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:2.6.2</extension>
        </extensions>
    </configuration>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>xsdtojava</goal>
            </goals>
            <configuration>
                <sourceRoot>${basedir}/target/generated-sources/xjc</sourceRoot>
                <xsdOptions>
                    <xsdOption>
<xsd>${basedir}/src/main/resources/osds/schemas/IataAsmAdmEvent.xsd</xsd>
<xsd>${basedir}/src/main/resources/osds/schemas/IataAsmCnlEvent.xsd</xsd>
<xsd>${basedir}/src/main/resources/osds/schemas/IataAsmEqtEvent.xsd</xsd>
<packagename>com.mypackage</packagename>
                    </xsdOption>
                </xsdOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

With this plugin, and many others, I am only able to generate an ObjectFactory with only the last schema in the list. None of the previous xsds make in the OF as java objects. Can anyone please help me solve this?

Thanks!

2

There are 2 answers

2
comonad On

I had the same problem, could solve that with a wrapper XSD:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:include schemaLocation="schema1.xsd" />
    <xs:include schemaLocation="schema2.xsd" />
    <xs:include schemaLocation="schema3.xsd" />
</xs:schema>

Of course this does not allow these included XSDs to include each other or common other XSDs. If "schema3.xsd" includes "schema2.xsd", remove "schema2.xsd" from this list.

0
Prasann On

Can be done using org.codehaus.mojo plugin. Provide multiple schema files under the 'schemaFiles' tag:

                <execution>
                    <id>xjc-generate-sources</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                    <configuration>
                        <extension>true</extension>
                        <schemaDirectory>src/main/resources/xsd</schemaDirectory>
                        <schemaFiles>xsd1.xsd,xsd2.xsd</schemaFiles>
                        <packageName>pachage.name.to.generate.classes</packageName>
                        <outputDirectory>target/generated-sources</outputDirectory>
                        <clearOutputDir>false</clearOutputDir>
                    </configuration>
                </execution>