CXF忽略sourceRoot配置参数

时间:2012-10-12 11:56:24

标签: java wsdl cxf maven-plugin

我正在使用CXF maven插件从wsdl生成Java类

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>${cxf-codegen-plugin.version}</version>
    <executions>
        <execution>
            <id>wsdl2java</id>
            <configuration>
                <sourceRoot>src/main/generated</sourceRoot>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>src/main/resources/wsdl/contentprovidercallback.wsdl</wsdl>
                        <extraargs>
                            <extraarg>-verbose</extraarg>
                            <extraarg>-frontend</extraarg>
                            <extraarg>jaxws21</extraarg>
                            <extraarg>-b</extraarg>
                            <extraarg>src/main/resources/wsdl/jaxws-contentprovidercallback.xml</extraarg>
                            <extraarg>-d</extraarg>
                            <extraarg>src/main/generated</extraarg>
                            <extraarg>-faultSerialVersionUID</extraarg>
                            <extraarg>FQCN</extraarg>
                            <extraarg>-xjc-Xts</extraarg>
                            <extraarg>-xjc-XhashCode</extraarg>
                            <extraarg>-xjc-Xequals</extraarg>
                        </extraargs>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.woodstox</groupId>
            <artifactId>stax2-api</artifactId>
            <version>${stax2.api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf.xjcplugins</groupId>
            <artifactId>cxf-xjc-ts</artifactId>
            <version>${cxf.xjc.ts.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>jaxb2-basics</artifactId>
            <version>${jaxb2.basics.version}</version>
        </dependency>
    </dependencies>
</plugin>

当我尝试执行cxf-codegen:wsdl2java目标时,生成的类不会在已定义的sourceRoot目录中生成。

当我使用调试选项(-X -e)运行mvn时,我得到了:

...
[DEBUG] Configuring mojo org.apache.cxf:cxf-codegen-plugin:2.6.1:wsdl2java from plugin realm ClassRealm[plugin>org.apache.cxf:cxf-codegen-plugin:2.6.1, parent: sun.misc.Launcher$AppClassLoader@425224ee]
[DEBUG] Configuring mojo 'org.apache.cxf:cxf-codegen-plugin:2.6.1:wsdl2java' with basic configurator -->
[DEBUG]   (f) classesDirectory = C:\WsdlTest\target\classes
[DEBUG]   (f) disableDependencyScan = false
[DEBUG]   (f) disableDirectoryScan = false
[DEBUG]   (f) encoding = UTF-8
[DEBUG]   (f) fork = false
[DEBUG]   (f) javaExecutable = C:\Program Files\Java\jdk1.6.0_31\jre/bin/java
[DEBUG]   (f) localRepository =        id: local
      url: file:///C:/Users/admi/.m2/repository/
   layout: none

[DEBUG]   (f) markerDirectory = C:\WsdlTest\target\cxf-codegen-plugin-markers
[DEBUG]   (f) mavenSession = org.apache.maven.execution.MavenSession@59cc5d23
[DEBUG]   (f) pluginArtifacts = [org.apache.cxf:cxf-codegen-plugin:maven-plugin:2.6.1:, org.codehaus.woodstox:stax2-api:jar:3.0.2:runtime, javax.xml.stream:stax-api:jar:1.0-2:runtime, org.apache.cxf.xjcplugins:cxf-xjc-ts:jar:2.4.0:runtime, commons-lang:commons-lang:jar:2.6:compile, org.jvnet.jaxb2_commons:jaxb2-basics:jar:0.6.3:runtime, org.jvnet.jaxb2_commons:jaxb2-basics-runtime:jar:0.6.3:runtime, org.jvnet.jaxb2_commons:jaxb2-basics-tools:jar:0.6.3:runtime, commons-beanutils:commons-beanutils:jar:1.7.0:runtime, org.apache.maven.shared:maven-artifact-resolver:jar:1.0:compile, org.codehaus.plexus:plexus-utils:jar:2.0.5:compile, org.codehaus.plexus:plexus-archiver:jar:1.2:compile, org.codehaus.plexus:plexus-io:jar:1.0.1:compile, org.apache.cxf:cxf-api:jar:2.6.1:compile, org.codehaus.woodstox:woodstox-core-asl:jar:4.1.2:runtime, org.apache.ws.xmlschema:xmlschema-core:jar:2.0.2:compile, org.apache.geronimo.specs:geronimo-javamail_1.4_spec:jar:1.7.1:compile, wsdl4j:wsdl4j:jar:1.6.2:compile, org.apache.cxf:cxf-tools-common:jar:2.6.1:compile, org.apache.velocity:velocity:jar:1.7:compile, commons-collections:commons-collections:jar:3.2.1:compile, com.sun.xml.bind:jaxb-xjc:jar:2.1.13:compile, com.sun.xml.bind:jaxb-impl:jar:2.1.13:compile, org.apache.cxf:cxf-rt-core:jar:2.6.1:compile, org.apache.cxf:cxf-tools-wsdlto-core:jar:2.6.1:compile, org.apache.cxf:cxf-tools-validator:jar:2.6.1:compile, org.apache.cxf:cxf-rt-bindings-soap:jar:2.6.1:compile, org.apache.cxf:cxf-rt-databinding-jaxb:jar:2.6.1:compile, org.apache.cxf:cxf-tools-wsdlto-databinding-jaxb:jar:2.6.1:compile, org.apache.cxf:cxf-tools-wsdlto-frontend-jaxws:jar:2.6.1:compile, xml-resolver:xml-resolver:jar:1.2:compile, org.apache.cxf:cxf-tools-wsdlto-frontend-javascript:jar:2.6.1:compile, org.apache.cxf:cxf-rt-javascript:jar:2.6.1:compile, org.springframework:spring-core:jar:3.0.7.RELEASE:compile, org.springframework:spring-asm:jar:3.0.7.RELEASE:compile, commons-logging:commons-logging:jar:1.1.1:compile, org.springframework:spring-beans:jar:3.0.7.RELEASE:compile, org.springframework:spring-context:jar:3.0.7.RELEASE:compile, org.springframework:spring-aop:jar:3.0.7.RELEASE:compile, aopalliance:aopalliance:jar:1.0:compile, org.springframework:spring-expression:jar:3.0.7.RELEASE:compile, org.apache.ant:ant:jar:1.8.2:compile, org.apache.ant:ant-launcher:jar:1.8.2:compile, org.apache.ant:ant-nodeps:jar:1.8.1:compile]
[DEBUG]   (f) project = MavenProject: com.tmobile.tmo.pfw:ssa:1.0.0-SNAPSHOT @ C:\WsdlTest\pom.xml
[DEBUG]   (f) repositories = [id = 'releases', id = 'snapshots', id = 'central']
[DEBUG]   (f) sourceRoot = C:\WsdlTest\target\generated-sources\cxf
[DEBUG]   (f) testWsdlRoot = C:\WsdlTest\src\test\resources\wsdl
[DEBUG]   (f) useCompileClasspath = false
[DEBUG]   (f) wsdlRoot = C:\WsdlTest\src\main\resources\wsdl
[DEBUG] -- end configuration --
...

另一方面,mvn clean install期间生成的资源很好(在生成的文件夹中)。但是我不希望每次构建都生成这些类。

知道什么是错的吗?

1 个答案:

答案 0 :(得分:3)

这个问题已经很老了,但我遇到了同样的问题,想要为未来保存解决方案:

不知何故cxf-codegen-plugin需要执行一些maven阶段才能“抓取”配置元素而不是使用默认值。我所做的是从默认构建中删除插件并创建一个配置文件,只是为了能够将其作为一部分运行 generate-sources按需提供,而不是每次构建。

我的样子如下:

<profile>
    <id>generate-ws-stub</id>
    <activation>
        <activeByDefault>false</activeByDefault>
    </activation>
    <properties>
        <version.cxf>2.3.0</version.cxf>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${version.cxf}</version>

                <dependencies>
                    <dependency>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-rt-transports-http</artifactId>
                        <version>${version.cxf}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-rt-ws-security</artifactId>
                        <version>${version.cxf}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-rt-core</artifactId>
                        <version>${version.cxf}</version>
                    </dependency>
                </dependencies>    

                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <sourceRoot>${project.build.sourceDirectory}\prb</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${project.build.resources[0].directory}/wsdl/NoneOfYourBusinessWS.wsdl</wsdl>
                                    <wsdlLocation>classpath:wsdl/NoneOfYourBusinessWS.wsdl</wsdlLocation>
                                    <extraargs>
                                        <extraarg>-verbose</extraarg>
                                        <extraarg>-impl</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

现在,每当我想“刷新”我的XML绑定时,我就会运行mvn generate-sources -P generate-ws-stub