【问题标题】:apache cxf-codegen-plugin wsdl2java ignore WSDL optionsapache cxf-codegen-plugin wsdl2java 忽略 WSDL 选项
【发布时间】:2021-04-26 12:33:21
【问题描述】:

我需要从两个 wsdl 文件生成 java 代码。下面的 pom.xml 对我有用。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         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>

    <groupId>br.com.luvva</groupId>
    <artifactId>cxf-test</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <properties>
        <cxf.sourceRoot>${project.build.directory}/generated-sources/annotations</cxf.sourceRoot>
        <cxf.version>3.4.2</cxf.version>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${cxf.version}</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <configuration>
                            <wsdlRoot>${project.basedir}/src/main/resources/wsdl</wsdlRoot>
                            <includes>
                                <include>*.wsdl</include>
                            </includes>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

问题在于这些 wsdl 文件声明了一些具有相同名称和名称空间的元素。因此,其中一个在代码生成期间覆盖另一个。我尝试了以下 pom.xml,但所有配置都被忽略了。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         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>

    <groupId>br.com.luvva</groupId>
    <artifactId>cxf-test-2</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <properties>
        <cxf.version>3.4.2</cxf.version>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${cxf.version}</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <configuration>
                            <sourceRoot>${project.build.directory}/generated-sources/annotations</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/vw_proposals.wsdl</wsdl>
                                    <extraargs>
                                        <extraarg>-P</extraarg>
                                        <extraarg>http://www.vwfsbr.com.br/servicebus=br.com.vwfsbr.proposals</extraarg>
                                    </extraargs>
                                </wsdlOption>
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/vw_tables.wsdl</wsdl>
                                    <extraargs>
                                        <extraarg>-P</extraarg>
                                        <extraarg>http://www.vwfsbr.com.br/servicebus=br.com.vwfsbr.tables</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

我怎样才能使插件正常工作?我还尝试了 -autoNameResolution 和 packageNames。没有任何效果,就好像配置被忽略了一样。

wsdl 文件可用herehere。 (使用下面的命令下载它们)。

curl [link] >> [fileName]

【问题讨论】:

    标签: cxf maven-plugin wsdl2java


    【解决方案1】:

    直接执行插件时,配置被忽略。 当插件在 maven 生成源阶段运行时,配置并没有被忽略,它工作得很好。

    【讨论】:

      猜你喜欢
      • 2021-10-10
      • 2014-02-26
      • 2017-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-14
      • 2022-01-22
      • 2012-04-27
      相关资源
      最近更新 更多