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

2

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!

Omnivore answered 30/8, 2013 at 17:39 Comment(4)
This seems to work::: <plugin> <groupId>org.jvnet.jaxb2.maven2</groupId> <artifactId>maven-jaxb2-plugin</artifactId> <version>0.7.5</version> <executions> <execution> <id>generate-S1-and-S3</id> <goals> <goal>generate</goal> </goals> <configuration> <schemaDirectory>src/main/resources/schemas</schemaDirectory> <schemaIncludes> <include>S2.xsd</include> <include>S3.xsd</include> </schemaIncludes> </configuration> </execution> </executions> </plugin>Omnivore
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?Omnivore
Did you ever figure this out? I'm having the same issue unfortunately.Tripura
<xsd> element is only allowed once within <xsdOption>.Malvie
P
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.

Pilch answered 20/5, 2015 at 10:56 Comment(2)
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'Hecate
@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 'bcb.gov.br/GEN/GEN0020E.xsd'.Pilch
M
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>
Mcwherter answered 12/9, 2016 at 13:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.