使用maven cxf XJC插件的BadCommandLineException

时间:2014-06-16 13:08:30

标签: maven jaxb cxf

我正在使用CXF开发一个SOA项目来生成SOAP客户端 我需要使用cxf-xjc-boolean插件来处理Dozer映射和布尔属性,因此我按照http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html处的文档进行操作,现在我有以下pom.xml摘录:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
    ...
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>${cxf.version}</version>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <sourceRoot>${basedir}/src/main/java</sourceRoot>
                        <defaultOptions>
                            <frontEnd>jaxws21</frontEnd>
                        </defaultOptions>
                        <wsdlOptions>
                            <wsdlOption>
                                <wsdl>${basedir}/src/main/wsdl/My.wsdl</wsdl>
                                <wsdlLocation>classpath:wsdl/My.wsdl</wsdlLocation>
                                <extraargs>
                                    <extraarg>-xjc-Xboolean</extraarg>
                                </extraargs>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<dependencies>
            ...
    <dependency>
        <groupId>org.apache.cxf.xjcplugins</groupId>
        <artifactId>cxf-xjc-boolean</artifactId>
        <version>2.7.0</version>
    </dependency>
</dependencies>
</project>

当我运行generate-sources目标时(通过m2e Eclipse插件或comman dline)我收到此错误:

[ERROR] Failed to execute goal org.apache.cxf:cxf-codegen-plugin:2.7.3:wsdl2java (generate-sources) on project My-BL: Execution generate-sources of goal org.apache.cxf:cxf-codegen-plugin:2.7.3:wsdl2java failed: XJC reported 'BadCommandLineException' for -xjc argument:-extension -Xts -target 2.1

如何修复我的pom.xml以使plunig正常工作?

BTW我注意到插件的版本2.7.3(管理的,与我正在使用的CXF版本一致)在版本库中不可用,所以我使用的是2.7.0。这可能是个问题吗?

1 个答案:

答案 0 :(得分:1)

需要做两件事:

  1. 将cxf-xjc-boolean依赖项放在插件的<dependencies>中,而不是放在项目依赖项中。
  2. 正确的参数是bg(生成getXYZ()方法)或bgi(生成getXYZ()和isXYZ()方法)而不是boolean。< / p>

    <plugin>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-codegen-plugin</artifactId>
        <version>${cxf.version}</version>
        <executions>
            <execution>
                <id>generate-sources</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>wsdl2java</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <sourceRoot>${basedir}/target/generated-sources</sourceRoot>
            <wsdlOptions>
                <wsdlOption>
                    <wsdl>
                        ${basedir}/src/main/resources/PatientService.wsdl
                    </wsdl>
                    <wsdlLocation>classpath:PatientService.wsdl</wsdlLocation>
                    <extraargs>
                        <extraarg>-xjc-Xbgi</extraarg>
                    </extraargs>
                </wsdlOption>
            </wsdlOptions>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>org.apache.cxf.xjcplugins</groupId>
                <artifactId>cxf-xjc-boolean</artifactId>
                <version>2.7.0</version>
            </dependency>
        </dependencies>
    </plugin>