如何使用JAXB autoInheritance从WSDL生成类?

时间:2014-09-24 11:44:46

标签: java jaxb cxf xjc cxf-xjc-plugin

我正在从soap webservices wsdl生成java类。

请求不共享一个公共接口,但我希望它们实现一个,或扩展一个公共类。

因此我正在尝试使用xcj-plugin。声明

<extraarg>-xjc-XautoInheritance-xmlRootElementsImplement=com.path.to.BaseInterface</extraarg>

应该注意这一点,并让所有@XmlRootElement注释类自动实现定义的BaseInterface

但是生成的类没有它。没有类正在实现此接口。为什么?以下配置可能出现什么问题?

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <wsdlOptions>
                                <extraargs>
                                    <extraarg>-xjc-XautoInheritance-xmlRootElementsExtend=com.path.to.BaseClass</extraarg>
                                <extraarg>-xjc-XautoInheritance-xmlRootElementsImplement=com.path.to.BaseInterface</extraarg>
                                <extraarg>-fe</extraarg>
                                <extraarg>cxf</extraarg>
                                <extraarg>-mark-generated</extraarg>
                                </extraargs>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>com.sun.xml.bind</groupId>
                    <artifactId>jaxb-xjc</artifactId>
                    <version>2.2.10-b140310.1920</version>
                </dependency>
                    <dependency>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                            <version>0.8.2</version>
                     </dependency>
                <dependency>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics-runtime</artifactId>
                    <version>0.8.2</version>
                </dependency>
                <dependency>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics-jaxb-xjc</artifactId>
                    <version>2.2.4-1</version>
                </dependency>
                <dependency>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb-xjc</artifactId>
                    <version>2.1.10.1</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

1 个答案:

答案 0 :(得分:2)

请添加-xjc-XautoInheritance以激活插件。

有关JAXB2 Basics插件的CXF用法,请参阅the following page

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <wsdlOptions>
            <wsdlOption>
                <wsdl>${basedir}/src/main/wsdl/CustomerService.wsdl</wsdl>
                <bindingFiles>
                    <bindingFile>${basedir}/src/main/wsdl/binding.xml</bindingFile>
                    <bindingFile>${basedir}/src/main/wsdl/binding.xjb</bindingFile>
                </bindingFiles>
                <extraargs>
                    <extraarg>-xjc-XhashCode</extraarg>
                    <extraarg>-xjc-Xequals</extraarg>
                </extraargs>
            </wsdlOption>
        </wsdlOptions>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>jaxb2-basics</artifactId>
            <version><!-- version --></version>
        </dependency>
    </dependencies>
</plugin>

免责声明:我是JAXB2 Basics插件的作者。