java - maven-jaxb2-plugin 两个具有相同元素的 xsd
问题描述
我有两个 xsd(样本被简化):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://someurl.com" xmlns="http://someurl.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" elementFormDefault="qualified">
<xs:element name="Request">
<xs:complexType>
<xs:sequence>
<xs:element name="Users" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="User" type="UserType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="UserType" type="xs:string" minOccurs="0" maxOccurs="1">
</xs:element>
</xs:schema>
和
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://otherurl.com" xmlns="http://otherurl.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" elementFormDefault="qualified">
<xs:element name="Request">
<xs:complexType>
<xs:sequence>
<xs:element name="Users" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="User" type="UserType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="UserType" type="xs:string" minOccurs="0" maxOccurs="1">
</xs:element>
</xs:schema>
我需要将 Request 元素生成到不同的包或具有不同类名的相同包中(如果可能的话)。并且所有子元素都放在同一个包中,因此例如它不会生成两个名为 UserType 的类。
这就是我现在在 pom.xml 中生成它的方式(但在这种情况下它的问题是因为生成了两个不同的 UserType 类):
<execution>
<id>xsd1</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<schemaIncludes>
<include>xsd1.xsd</include>
</schemaIncludes>
<bindingDirectory>src/main/resources/xsd</bindingDirectory>
<bindingIncludes>
<include>edu.xjb</include>
</bindingIncludes>
<generateDirectory>${project.basedir}/target/generated-sources/jaxb/schemas/xsd1</generateDirectory>
<generatePackage>mainpackage.package1</generatePackage>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.9.4</version>
</plugin>
</plugins>
<args>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
<arg>-XtoString</arg>
</args>
</configuration>
</execution>
和
<execution>
<id>xsd2</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<schemaIncludes>
<include>xsd2.xsd</include>
</schemaIncludes>
<bindingDirectory>src/main/resources/xsd</bindingDirectory>
<bindingIncludes>
<include>edu.xjb</include>
</bindingIncludes>
<generateDirectory>${project.basedir}/target/generated-sources/jaxb/schemas/xsd2</generateDirectory>
<generatePackage>mainpackage.package2</generatePackage>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.9.4</version>
</plugin>
</plugins>
<args>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
<arg>-XtoString</arg>
</args>
</configuration>
</execution>
解决方案
推荐阅读
- django - Django 过滤 URL 和 VIEWS - “在 /collection/... 找不到页面”
- java - 我不懂一行编程代码
- php - 如何更正在 PDO 中运行准备好的语句的功能
- html - 在固定位置显示按钮
- java - 使用 for 循环将重复项插入到 StringBuilder 的方法
- reactjs - 子组件不会重新渲染
- django - 守护 Celery——没有名为“celery”的模块错误
- c++ - C++ 可执行文件在运行时找不到库,即使它位于 /usr/lib 中(在 Linux 上)
- javascript - 如何在移动到下一页之前为每个元素的 jquery 函数设置动画
- javascript - 如何根据下拉菜单更新数据源?