Java 如何为重复的元素名绑定jaxb2模式
我试图从多个xsd文件生成java类。 在这些模式文件中,在不同的模式中有多个complexType或同名元素Java 如何为重复的元素名绑定jaxb2模式,java,jaxb,maven-jaxb2-plugin,jaxb2-maven-plugin,Java,Jaxb,Maven Jaxb2 Plugin,Jaxb2 Maven Plugin,我试图从多个xsd文件生成java类。 在这些模式文件中,在不同的模式中有多个complexType或同名元素 请注意,我无法更改模式 我创建了一个绑定文件,但仍然出现此错误 示例_QualifyRQ.xsd;…'myelement'已定义 我的配置中有什么遗漏吗 所有架构都位于1个目录中,例如: xsd: 示例_QualifyRS.xsd 示例_QualifyRQ.xsd 示例_PurchaseRQ.xsd 示例_CommonTypes.xsd 示例_simpleType.xsd 示例_Q
请注意,我无法更改模式 我创建了一个绑定文件,但仍然出现此错误 示例_QualifyRQ.xsd;…'myelement'已定义 我的配置中有什么遗漏吗 所有架构都位于1个目录中,例如: xsd:
- 示例_QualifyRS.xsd
- 示例_QualifyRQ.xsd
- 示例_PurchaseRQ.xsd
- 示例_CommonTypes.xsd
- 示例_simpleType.xsd
<xs:schema xmlns="http://www.example.org/EXAMPLE/2007/00" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/EXAMPLE/2007/00"
elementFormDefault="qualified" version="1.002" id="EXAMPLE2016.1">
<xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/>
<xs:element name="myelement">...</xs:element>
...
示例_QualifyRQ.xsd
<xs:schema xmlns="http://www.example.org/EXAMPLE/2007/00" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/EXAMPLE/2007/00"
elementFormDefault="qualified" version="1.002" id="EXAMPLE2016.1">
<xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/>
<xs:element name="myelement">...</xs:element>
...
示例_PurchaseRQ.xsd
<xs:schema xmlns="http://www.example.org/EXAMPLE/2007/00" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/EXAMPLE/2007/00" elementFormDefault="qualified" version="1.001" id="EXAMPLE2016.1">
<xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/>
<xs:include schemaLocation="EXAMPLE_SimpleTypes.xsd"/>
<xs:element name="myelement">...</xs:element>
...
下面是我如何在maven中生成我的类
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>example-schema</id>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<xsdPathWithinArtifact>xsd</xsdPathWithinArtifact>
<addGeneratedAnnotation>true</addGeneratedAnnotation>
<laxSchemaValidation>true</laxSchemaValidation>
<laxSchemaValidation>true</laxSchemaValidation>
<readOnly>true</readOnly>
<verbose>true</verbose>
<sources>
<source>src/main/resources/xsd</source>
</sources>
<xjbSources>
<xjbSource>src/main/resources/xjb</xjbSource>
</xjbSources>
</configuration>
</execution>
</executions>
</plugin>
org.codehaus.mojo
jaxb2 maven插件
2.4
示例模式
生成源
xjc
xsd
真的
真的
真的
真的
真的
src/main/resources/xsd
src/main/resources/xjb
还有我的装订
<?xml version="1.0" encoding="UTF-8"?>
<bindings version="2.1"
xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
extensionBindingPrefixes="xjc">
<globalBindings>
<serializable uid="1"/>
<xjc:javaType name="java.time.LocalDateTime" xmlType="xs:dateTime" adapter="com.example.adapter.LocalDateTimeAdapter"/>
<xjc:javaType name="java.time.LocalDate" xmlType="xsd:date" adapter="com.example.adapter.LocalDateAdapter"/>
</globalBindings>
<bindings schemaLocation="../xsd/EXAMPLE_QualifyRS.xsd" node="/xs:schema">
<schemaBindings>
<package name="com.example.qualify.response"/>
</schemaBindings>
<bindings node="//xs:element[@name='myelement']">
<class name="QualifyMyElement"/>
</bindings>
</bindings>
<bindings schemaLocation="../xsd/EXAMPLE_QualifyRQ.xsd" node="/xs:schema">
<schemaBindings>
<package name="com.example.qualify.request"/>
</schemaBindings>
<bindings node="//xs:element[@name='myelement']">
<class name="QualifyMyElement"/>
</bindings>
</bindings>
<bindings schemaLocation="../xsd/EXAMPLE_PurchaseRQ.xsd" node="/xs:schema">
<schemaBindings>
<package name="com.example.purchase"/>
</schemaBindings>
<bindings node="//xs:element[@name='myelement']">
<class name="PurchaceMyElement"/>
</bindings>
</bindings>
</bindings>
在绑定中,您有示例限定符和示例采购器。错误来自示例_QualifyRQ。也许“myelement”是在示例_QualifyRQ和其他模式中定义的?添加绑定,例如_QualifyRQ,看看它是否有效或者消息是否更改。我道歉。在我的问题上,我遗漏了EXAMPLE_QualifyRQ.xsd。我已经用示例_QualifyRQ详细信息更新了上面的问题。我还尝试将示例_QualifyRS(com.EXAMPLE.qualify.response)绑定到与示例_QualifyRQ(com.EXAMPLE.qualify.request)不同的包。我的绑定似乎仍然不起作用。问题是您的所有架构都具有相同的目标命名空间。但我无法更改架构。是否可以根据文件模式在组中生成它们?例如,“*Purchase.xsd”转到“example.Purchase”,检查example_CommonTypes.xsd和example_SimpleTypes.xsd中是否都有“myElement”。从我在绑定中看到的情况来看,您没有为此模式生成的类指定包名。示例_QualifyRQ中有两个模式。