使用“cxf xjc plugin”生成的类不能正确导入其他生成的类

jmp7cifd  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(234)

我想从多个相互依赖的xsd文件中生成java类。
因为我使用的是Java11,所以我尝试使用用于maven的CXFXJC插件来实现这一点。
生成部分在大多数情况下工作正常,但有一个:
导入其他生成的类型
例如,我有一个(生成的)类,它应该导入另一个生成的类。它将如下生成:

public class FATCAFileErrorNotificationType implements NotificationInterface {
    @XmlElement(name = "FATCANotificationHeaderGrp", namespace = "urn:fatca:fatcanotificationbase", required = true)
    protected FATCANotificationHeaderGrpType fatcaNotificationHeaderGrp;
    @XmlElement(name = "OriginalFileMetadataGrp", namespace = "urn:fatca:fatcanotificationbase", required = true)
    protected OriginalFileMetadataGrpType originalFileMetadataGrp;
    @XmlElement(name = "HCTATreatyStampTxt", namespace = "urn:fatca:fatcanotificationbase")
    protected String hctaTreatyStampTxt;
....

简单的数据类型 String 或者 int 按我的期望去做,但是更复杂的事情,比如(生成的) FATCANotificationHeaderGrpType 发出错误,因为无法导入它们。
但是,如果我像这样添加包名(fatca),就可以了:

public class FATCAFileErrorNotificationType implements NotificationInterface {
    @XmlElement(name = "FATCANotificationHeaderGrp", namespace = "urn:fatca:fatcanotificationbase", required = true)
    protected fatca.FATCANotificationHeaderGrpType fatcaNotificationHeaderGrp;
    @XmlElement(name = "OriginalFileMetadataGrp", namespace = "urn:fatca:fatcanotificationbase", required = true)
    protected fatca.OriginalFileMetadataGrpType originalFileMetadataGrp;
    @XmlElement(name = "HCTATreatyStampTxt", namespace = "urn:fatca:fatcanotificationbase")
    protected String hctaTreatyStampTxt;
....

我已经尝试更改包名或xsd,但都没有用。
如果有帮助,这是我的插件配置

<plugin>
               <groupId>org.apache.cxf</groupId>
               <artifactId>cxf-xjc-plugin</artifactId>
               <version>3.3.1</version>
               <executions>
                   <execution>
                       <id>xjc</id>
                       <phase>generate-sources</phase>
                       <goals>
                           <goal>xsdtojava</goal>
                       </goals>
                       <configuration>
                           <xsdOptions>
                               <xsdOption>
                                   <xsdDir>${basedir}/src/main/resources/xsd</xsdDir>
                                   <packagename>fatca</packagename>
                                   <extension>true</extension>
                                   <bindingFile>${basedir}/src/main/resources/xjb/bindings.xjb</bindingFile>
                                   <extensionArgs>
                                       <extensionArg>-Xinheritance</extensionArg>
                                   </extensionArgs>
                               </xsdOption>
                           </xsdOptions>
                           <extensions>
                               <extension>org.jvnet.jaxb2_commons:jaxb2-basics:1.11.1</extension>
                           </extensions>
                       </configuration>
                   </execution>
               </executions>
           </plugin>

我还使用以下配置向生成的类添加了一个接口:

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings version="2.1"
               xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
               jaxb:extensionBindingPrefixes="xjc">
    <jaxb:bindings
            schemaLocation="../xsd/FATCA-FILE-ERROR-NOTIFICATION-2.5.xsd"
            node="//xs:complexType[@name='FATCAFileErrorNotificationType']">
        <inheritance:implements>NotificationInterface
        </inheritance:implements>
    </jaxb:bindings>
    <jaxb:bindings
            schemaLocation="../xsd/FATCA-VALID-FILE-NOTIFICATION-2.5.xsd"
            node="//xs:complexType[@name='FATCAValidFileNotificationType']">
        <inheritance:implements>NotificationInterface
        </inheritance:implements>
    </jaxb:bindings>
</jaxb:bindings>

Thanks in advance for any answers

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题