0

由于以下错误,我没有使用cxf-xjc maven 插件为 Java生成任何类:

[错误]两个声明导致 ObjectFactory 类中的冲突。文件第 21 行 :/C:/../IdeaProjects/CXFDocInstanceGenerator/XSDToClassGenerator/src/main/resources/IntegralAdmission_bis.xsd

生成涉及到3个xsd

  • PExGeneraReport_bis.xsd(使用下面的其他两个)
  • PartialAdmission_bis.xsd
  • IntegralAdmission_bis.xsd

最后两个 xsd 在以下元素上产生冲突:

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

包含在两个 xsd 中(PartialAdmission_bis.xsd 和 IntegralAdmission_bis.xsd

我使用了以下最后一个外部绑定条件:解决问题(连同许多其他尝试)但没有成功!

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

除了 factoryMethod 名称之外,我还使用jxb:class 和 jxb:elementName没有成功。没有生成类

在一个 xsd 设置中更改元素名称:

xs:元素名称= “模IA ”类型=“模”

解决了这个问题,但我需要维护“模”作为编组的 xml 元素的名称,所以我只需要更改与 java 类或方法名称的绑定!关于设置正确绑定以解决问题的任何想法?

正如@lexicore 在评论中所问的那样,我在下文中报告了该项目的 [mcve]: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>

绑定PExGeneraReport_bis.xsd的主要 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>
  • 第一个导入的 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>
    

第二个与上面的 xsd (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>

绑定文件:

<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>

项目目录:

在此处输入图像描述

4

0 回答 0