cxf-xjc-plugin not generating java classes due to collision in ObjectFactory class

2.1k Views Asked by At

I got no class generated with cxf-xjc maven plugin for Java due to the following error:

[ERROR] Two declarations cause a collision in the ObjectFactory class. line 21 of file:/C:/../IdeaProjects/CXFDocInstanceGenerator/XSDToClassGenerator/src/main/resources/IntegralAdmission_bis.xsd

there are 3 xsds involved in the generation

  • PExGeneraReport_bis.xsd (that uses the other two bellow)
  • PartialAdmission_bis.xsd
  • IntegralAdmission_bis.xsd

the last two xsd are generating the conflict on the following element:

<xs:group name="RootGroup">
    <xs:sequence>
        <xs:element name="modulo" type="Modulo">
        </xs:element>
    </xs:sequence>
</xs:group>

contained in both xsds (PartialAdmission_bis.xsd and IntegralAdmission_bis.xsd)

I used the following last external binding condition : to solve the problem (together with a lot of other tries) without success!

<jxb:bindings schemaLocation="IntegralAdmission_bis.xsd">
    <jxb:bindings node="//xs:element[@name='modulo']">
        <jxb:factoryMethod name="ModuloAccoglimentoIntegrale"/>
    </jxb:bindings>
</jxb:bindings>

beside factoryMethod name i use also jxb:class and jxb:elementName without success. No classes are generated

Changing the element name in one xsd setting:

xs:element name="moduloIA" type="Modulo"

solves the problem but i need to maintain 'modulo' as the name of the xml element for the marshalling and so I need to change only the binding to java classes or method name! Any Idea on the correct binding to set to solve the problem?

As asked by in the comments by @lexicore, I report hereafter an [mcve] of the project: the pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>

    <groupId>CXFDocInstanceGenerator</groupId>
    <artifactId>MCVE_XSDToClassGenerator</artifactId>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.9</source>
                        <target>1.9</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-xjc-plugin</artifactId>
                <version>2.3.0</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>
                        <goals>
                            <goal>xsdtojava</goal>
                        </goals>
                        <configuration>
                            <sourceRoot>${project.build.sourceDirectory}</sourceRoot>
                            <xsdOptions>
                                <xsdOption>
                                    <xsd>${project.basedir}/src/main/resources/PExGeneraReport_bis.xsd</xsd>
                                    <!--bindingFile>${project.basedir}/src/main/resources/dgPEXGR.xjb</bindingFile-->
                                    <extension>true</extension>
                                </xsdOption>
                            </xsdOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
    </dependencies>

</project>

the main xsd to bind PExGeneraReport_bis.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:aci="urn://IntegralAdmission_bis"
           xmlns:acp="urn://PartialAdmission_bis"
           xmlns="urn://GenerateReport"
           targetNamespace="urn://GenerateReport"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified"
>
    <xs:import namespace="urn://IntegralAdmission_bis" schemaLocation="IntegralAdmission_bis.xsd"/>
    <xs:import namespace="urn://PartialAdmission_bis" schemaLocation="PartialAdmission_bis.xsd"/>

    <xs:element name="root" type="Root"/>

    <xs:complexType name="Root">
        <xs:sequence>
            <xs:element name="frontespizioPostel" type="xs:string"/>
            <xs:group ref="RootGroup"/>
        </xs:sequence>
    </xs:complexType>

    <xs:group name="RootGroup">
        <xs:sequence>
            <xs:choice>
                <xs:group ref="aci:RootGroup"/>
                <xs:group ref="acp:RootGroup"/>
            </xs:choice>
            <!--xs:element name="metadati" type="Metadati"/-->
        </xs:sequence>
    </xs:group>

</xs:schema>
  • the first imported xsd IntegralAdmission_bis.xsd

    <xs:element name="root" type="Root"/>
    
    <xs:complexType name="Root">
        <xs:sequence>
            <xs:element name="frontespizioPostel" type="xs:string"/>
            <xs:group ref="RootGroup"/>
        </xs:sequence>
    </xs:complexType>
    
    <xs:group name="RootGroup">
        <xs:sequence>
            <xs:element name="modulo" type="Modulo">
            </xs:element>
        </xs:sequence>
    </xs:group>
    
    <xs:complexType name="Modulo">
        <xs:sequence>
            <xs:element name="denominazioneAzienda" type="xs:string"/>
            <xs:element name="indirizzo" type="xs:string"/>
            <xs:element name="pecAzienda" type="xs:string"/>
            <xs:element name="dataProvvedimento" type="xs:date"/>
            <xs:element name="tipoPrestazione" type="xs:string"/>
            <xs:element name="numeroProtocollo" type="xs:string"/>
            <xs:element name="numeroProvvedimento" type="xs:string"/>
            <xs:element name="annoProvvedimento" type="xs:string"/>
            <xs:element name="dataPresentazione" type="xs:date"/>
        </xs:sequence>
    </xs:complexType>
    

The second one conflicting with the xsd above (IntegralAdmission_bis.xsd) PartialAdmission_bis.xsd:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.0"
    xmlns="urn://PartialAdmission_bis"
    targetNamespace="urn://PartialAdmission_bis"
    elementFormDefault="qualified" 
    attributeFormDefault="qualified">

    <xs:element name="root" type="Root"/>

    <xs:complexType name="Root">
        <xs:sequence>
            <xs:element name="frontespizioPostel" type="xs:string"/>
            <xs:group ref="RootGroup"/>
        </xs:sequence>
    </xs:complexType>

    <xs:group name="RootGroup">
        <xs:sequence>
            <xs:element name="modulo" type="Modulo">
            </xs:element>
        </xs:sequence>
    </xs:group>

    <xs:complexType name="Modulo">
        <xs:sequence>
            <xs:element name="denominazioneAzienda" type="xs:string"/>
            <xs:element name="indirizzo" type="xs:string"/>
            <xs:element name="pecAzienda" type="xs:string"/>
            <xs:element name="dataProvvedimento" type="xs:date"/>
            <xs:element name="tipoPrestazione" type="xs:string"/>
            <xs:element name="numeroProtocollo" type="xs:string"/>
            <xs:element name="numeroProvvedimento" type="xs:string"/>
            <xs:element name="annoProvvedimento" type="xs:string"/>
            <xs:element name="dataPresentazione" type="xs:date"/>
            <xs:element name="causale" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

Binding file:

<jxb:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
              xmlns:xs="http://www.w3.org/2001/XMLSchema"
              version="2.1">
    <jxb:bindings schemaLocation="IntegralAdmission_bis.xsd">
        <jxb:bindings node="//xs:element[@name='modulo']">
            <jxb:factoryMethod name="ModuloAccoglimentoIntegrale"/>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>

Project directories:

enter image description here

0

There are 0 best solutions below