为相同类型生成外部绑定的 jaxb 多个 class
jaxb multiple class generated for same type incase of external bindings
我有以下架构和相应的绑定文件。我使用 jaxb2 maven 插件生成 JAXB 类.
person.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="pType" type="pType" minOccurs="0" />
<xs:element name="sex" type="xs:string"
minOccurs="1" />
<xs:element name="dob" type="xs:string"
minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- some more elements ignored for clarity.................
.......................... -->
<xs:complexType name="pType">
<xs:sequence>
<xs:element name="category" type="xs:string"
minOccurs="0" />
<xs:element name="blahh" type="xs:string"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:schema>
jaxb 绑定
<jxb:bindings schemaLocation="person.xsd">
<jxb:bindings node="//xs:complexType[@name='pType']">
<jxb:class name="PersonType" />
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="person.xsd">
<jxb:bindings
node="//xs:element[@name='person']//xs:element[@name='pType']">
<jxb:class ref="PersonType" />
</jxb:bindings>
</jxb:bindings>
我已定义绑定以将 <xs:complexType name="pType">
的名称覆盖为 PersonType
。在 XJC 生成时,它生成 PersonType.class 和 PType.class。
如果我在元素 <xs:element name="pType" >
内部定义 <xs:complexType name="pType">
,那么它不会生成 PType.class。
但是我必须在模式的根级别声明 <xs:complexType name="pType">
,因为这个 xs:complexType
也被其他模式引用。
我试图覆盖绑定中的 <xs:complexType name="pType">
和 <xs:element name="pType" >
,但生成了 PType.class。
我如何指示它不生成 PType.class?
问题是我对 maven-jaxb2-plugin
中的每个模式(依赖模式 person2.xsd
和 person.xsd
)执行了 2 次。所以我手动编写了 episode
文件来引用已经创建的 <xs:complexType name="pType">
并解决了这个问题。
为了有同样问题的人的利益,这里是插件执行细节和 episode
文件。请注意,我没有使用 namespaces
因此您会发现 scd
没有命名空间很简单。
人集
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" if-exists="true" version="2.1">
<jaxb:bindings scd="x-schema::">
<jaxb:bindings scd="/type::pType">
<jaxb:class ref="org.wipo.pct.test.PersonType"/>
<jaxb:package name="org.wipo.pct.test" />
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
pom.xml
<execution>
<id>person</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaIncludes>
<include>person.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>pbindings.xjb</include>
</bindingIncludes>
<verbose>true</verbose>
</configuration>
</execution>
<execution>
<id>person2</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaIncludes>
<include>person2.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>pbindings2.xjb</include>
</bindingIncludes>
<verbose>true</verbose>
<args>
<arg>-b</arg>
<arg>src/main/resources/person-episode</arg>
<arg>-Xsimplify</arg>
<arg>-Xinheritance</arg>
</args>
</configuration>
</execution>
我有以下架构和相应的绑定文件。我使用 jaxb2 maven 插件生成 JAXB 类.
person.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="pType" type="pType" minOccurs="0" />
<xs:element name="sex" type="xs:string"
minOccurs="1" />
<xs:element name="dob" type="xs:string"
minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- some more elements ignored for clarity.................
.......................... -->
<xs:complexType name="pType">
<xs:sequence>
<xs:element name="category" type="xs:string"
minOccurs="0" />
<xs:element name="blahh" type="xs:string"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:schema>
jaxb 绑定
<jxb:bindings schemaLocation="person.xsd">
<jxb:bindings node="//xs:complexType[@name='pType']">
<jxb:class name="PersonType" />
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="person.xsd">
<jxb:bindings
node="//xs:element[@name='person']//xs:element[@name='pType']">
<jxb:class ref="PersonType" />
</jxb:bindings>
</jxb:bindings>
我已定义绑定以将 <xs:complexType name="pType">
的名称覆盖为 PersonType
。在 XJC 生成时,它生成 PersonType.class 和 PType.class。
如果我在元素 <xs:element name="pType" >
内部定义 <xs:complexType name="pType">
,那么它不会生成 PType.class。
但是我必须在模式的根级别声明 <xs:complexType name="pType">
,因为这个 xs:complexType
也被其他模式引用。
我试图覆盖绑定中的 <xs:complexType name="pType">
和 <xs:element name="pType" >
,但生成了 PType.class。
我如何指示它不生成 PType.class?
问题是我对 maven-jaxb2-plugin
中的每个模式(依赖模式 person2.xsd
和 person.xsd
)执行了 2 次。所以我手动编写了 episode
文件来引用已经创建的 <xs:complexType name="pType">
并解决了这个问题。
为了有同样问题的人的利益,这里是插件执行细节和 episode
文件。请注意,我没有使用 namespaces
因此您会发现 scd
没有命名空间很简单。
人集
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" if-exists="true" version="2.1">
<jaxb:bindings scd="x-schema::">
<jaxb:bindings scd="/type::pType">
<jaxb:class ref="org.wipo.pct.test.PersonType"/>
<jaxb:package name="org.wipo.pct.test" />
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
pom.xml
<execution>
<id>person</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaIncludes>
<include>person.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>pbindings.xjb</include>
</bindingIncludes>
<verbose>true</verbose>
</configuration>
</execution>
<execution>
<id>person2</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaIncludes>
<include>person2.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>pbindings2.xjb</include>
</bindingIncludes>
<verbose>true</verbose>
<args>
<arg>-b</arg>
<arg>src/main/resources/person-episode</arg>
<arg>-Xsimplify</arg>
<arg>-Xinheritance</arg>
</args>
</configuration>
</execution>