6

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!

user2733840
  • 61
  • 1
  • 2
  • This seems to work::: org.jvnet.jaxb2.maven2 maven-jaxb2-plugin 0.7.5 generate-S1-and-S3 generate src/main/resources/schemas S2.xsd S3.xsd – user2733840 Aug 30 '13 at 18:23
  • But eclipse is stuck in loop - building changes for the xsd generate sources, as well as building changes for the wsdl generate sources. It seems to ping pong back and forth and never resolve itself. Any ideas? – user2733840 Aug 30 '13 at 18:26
  • 1
    Did you ever figure this out? I'm having the same issue unfortunately. – Evan LaHurd Jan 26 '16 at 23:31
  • 1
    `` element is only allowed once within ``. – bjmi Oct 29 '21 at 10:34

2 Answers2

3

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.

comonad
  • 5,134
  • 2
  • 33
  • 31
  • I tried this method. I got one error for each included file: `[ERROR] src-include.2.1: The targetNamespace of the referenced schema, currently 'http://www.bcb.gov.br/GEN/GEN0020E.xsd', must be identical to that of the including schema, currently 'null'` – Pedro Lamarão Dec 22 '16 at 18:16
  • @PedroLamarão it seems that you mixed up different namespaces, where some of them are null. it could be that there are options to ignore namespaces (which i do not know of) or you have to set the namespace of each including schema to 'http://www.bcb.gov.br/GEN/GEN0020E.xsd'. – comonad Jan 05 '17 at 16:59
0

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>
Prasann
  • 1,263
  • 2
  • 11
  • 18