binding - 嵌入式绑定不适用于 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 Validation.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>
解决方案
原来,我不得不改变这一行:
- 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"
推荐阅读
- c++ - C++ 是否保证参数评估的原子性?
- python - 为什么我提示说scrapy中@class的语法无效?
- python - 从带有符号字符的字符串换行中提取整数的有效方法是什么?
- pip - windows Pycharm项目解释器没什么可显示的
- r - 无法在 R studio 中分配 2.8Gb 错误的向量
- c++ - 递归中的段错误,当尝试在 C++ 中的数独求解器算法中回溯时
- python - 合并/分组类实例
- android - Android Studio 4.0 未显示构建错误详细信息
- linux - $MKLROOT 未定义(Ubuntu)
- reactjs - 如何在 react-google-maps reactjs 中更改 infoWindow 样式