如何解决嵌入式绑定不适用于 jaxb xjc 3.0.0
我正在使用 jaxb 3.0.0 (xjc.sh) 来创建 Java 类,但出于某种原因,它不支持嵌入式绑定。同样的事情适用于 jaxb 2.3.1
$密码 /c/jaxb-ri-3.0.0/jaxb-ri/bin
$ ./xjc.sh 验证.xsd
它正在创建 ApiValidator.java,因为我希望它不会创建一个新的,而不是引用我作为嵌入式绑定的那个。
- a/model/ApiValidator.java
- a/model/ObjectFactory.java
- a/model/package-info.java
- a/model/ValidationAction.java
$ cat 验证.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="a/model"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0"
xmlns:tns="a/model" elementFormDefault="qualified">
<xs:attribute name="Description" type="xs:string"/>
<xs:attribute name="required" type="xs:boolean"/>
<xs:complexType name="ValidationAction">
<xs:sequence>
<xs:element name="api" type="xs:string" tns:Description="Indicates the validation API"/>
<xs:element name="method" type="xs:string" tns:Description="Indicates the validation method"/>
<xs:element name="beanName" type="xs:string" tns:Description="Validation bean name"/>
<xs:element name="validationClass" type="xs:string" tns:Description="Validation class type"/>
<xs:element name="idOwner" type="xs:int" tns:Description="Indicates the owner associated with the validation"/>
<xs:element name="valid" type="xs:boolean" tns:Description="Indicates if validation is valid"/>
<xs:element name="validator" type="tns:ApiValidator" minOccurs="0" maxOccurs="1"
tns:Description="Reference to the API validator"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ApiValidator">
<xs:annotation>
<xs:appinfo>
<jaxb:bindings node="//xs:complexType[@name='ApiValidator']">
<jaxb:class ref="a.ApiValidator"/>
</jaxb:bindings>
</xs:appinfo>
</xs:annotation>
</xs:complexType>
</xs:schema>
如果我用 2.3.1 版本做同样的事情, $ ./xjc.sh 验证.xsd Java 主要版本:8 解析模式... 编译模式...
- a\model\ObjectFactory.java
- a\model\ValidationAction.java
- a\model\package-info.java
我需要使用 3.0.0 版本,因为它会生成 jakarta 命名空间。请提出为什么它不起作用以及如何解决它?
此行为与下面提到的 xml 相同:
$ cat V.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="a/model"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0"
xmlns:tns="a/model" elementFormDefault="qualified">
<xs:attribute name="Description" type="xs:string"/>
<xs:attribute name="required" type="xs:boolean"/>
<xs:complexType name="ValidationAction">
<xs:sequence>
<xs:element name="api" type="xs:string" tns:Description="Indicates the validation API"/>
<xs:element name="method" type="xs:string" tns:Description="Indicates the validation method"/>
<xs:element name="beanName" type="xs:string" tns:Description="Validation bean name"/>
<xs:element name="validationClass" type="xs:string" tns:Description="Validation class type"/>
<xs:element name="idOwner" type="xs:int" tns:Description="Indicates the owner associated with the validation"/>
<xs:element name="valid" type="xs:boolean" tns:Description="Indicates if validation is valid"/>
<xs:element name="validator" type="tns:ApiValidator" minOccurs="0" maxOccurs="1"
tns:Description="Reference to the API validator"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ApiValidator">
<xs:annotation>
<xs:appinfo>
<jaxb:class ref="rd.ApiValidator"/>
</xs:appinfo>
</xs:annotation>
</xs:complexType>
</xs:schema>
如建议: Jaxb implClass specification ignored for rootElement
解决方法
结果,我不得不改变以下行:
- xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0"
- xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" jaxb:version="3.0"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。