由于以下错误,我没有使用 cxf-xjc Maven Java插件生成的类:
[错误] 两个声明在ObjectFactory类中引起冲突。 的第21行 文件:/ C:/../ IdeaProjects / CXFDocInstanceGenerator / XSDToClassGenerator / src / main / resources / IntegralAdmission_bis.xsd
这一代涉及3个xsds
最后两个xsd在以下元素上产生冲突:
<xs:group name="RootGroup">
<xs:sequence>
<xs:element name="modulo" type="Modulo">
</xs:element>
</xs:sequence>
</xs:group>
包含在两个xsds中(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>
除了factoryMethodName之外,我还使用 jxb:class和jxb:elementName 而不成功。 未生成任何课程
在一种xsd设置中更改元素名称:
xs:element name =“ moduloIA ” type =“ Modulo”
解决了问题,但我需要将“模数”作为编组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>
项目目录: