How can I disable .xsd validation in cxf-xjc-plugin?

1.8k Views Asked by At

I'm trying to generate Java sources from XSD files form a provider (I cannot change those files) files with the maven cxf-xjc-plugin.

Evertyhing was working fine, but I need to add a new .xsd file. This file includes other .xsd files inside and theres is a conflict because the new .xsd files defines entities with the same name as existing xsd files (I know, I know, but I am just a user of these .xsd files). Ah! they should be in the same package...

The error is the typical:

A schema cannot contain two global components with the same name; this schema contains two occurrences of ...

I've read that someone was able to fix similar issues telling to the tool he was using to NOT validate the .xsd.

I was wondering if it is possible to tell to the cxf-xjc-plugin no to validate .xsd files and just convert into Java

The maven configuration is as follows:

<plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-xjc-plugin</artifactId>
            <version>3.0.5</version>
            <configuration>
                <extensions>
                    <extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:2.3.0</extension>
                </extensions>
            </configuration>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <configuration>

                        <forceRegenerate>false</forceRegenerate>

                        <sourceRoot>${project.basedir}/src/main/java</sourceRoot>                           
                        <xsdOptions>
                            <xsdOption>
                                <xsd>${basedir}/src/main/resources/webapi/xsd/SuperSchemaCommon.xsd</xsd>                                   
                                <packagename>com.XX.XXXXX.package</packagename>
                                <extensionArgs>
                                    <arg>-encoding</arg>
                                    <arg>UTF-8</arg>
                                </extensionArgs>
                            </xsdOption>
                            <xsdOption>
                                <xsd>${basedir}/src/main/resources/webapi/xsd/SuperSchemaInput.xsd</xsd>
                                <bindingFile>${basedir}/src/main/xjb/pnr/SuperSchemaInput.xjb</bindingFile>
                                <packagename>com.XXXXXXX.input</packagename>
                                <extensionArgs>
                                    <arg>-encoding</arg>
                                    <arg>UTF-8</arg>
                                </extensionArgs>
                            </xsdOption>

                        </xsdOptions>       
                    </configuration>                        
                    <goals>
                        <goal>xsdtojava</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Thanks in advance!

1

There are 1 best solutions below

0
On

Solution found!

Simply adding the xjc parameter "-nv" as another extension arg. It is passed to the arguments of xjc when executing maven task

<xsdOption>
...
    <extensionArgs>
        <arg>-encoding</arg>
        <arg>UTF-8</arg>
        <arg>-nv</arg>
    </extensionArgs>
</xsdOption>