我有两个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>