【问题标题】:cxf-codegen-plugin not generating codecxf-codegen-plugin 不生成代码
【发布时间】:2015-10-28 04:46:33
【问题描述】:

我正在尝试使用 Maven 从 WSDL 生成 Java。我对 Maven 不是很熟悉,所以我遇到问题并不奇怪。

运行mvn generate-sources,我得到了这个输出

$ mvn generate-sources
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building data-mgmt-ws 1.0
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.188 s
[INFO] Finished at: 2015-10-27T23:19:20-05:00
[INFO] Final Memory: 5M/92M
[INFO] ------------------------------------------------------------------------

没有错误,但也没有类。

这是我的 POM 的相关部分:

<?xml version="1.0" encoding="UTF-8"?>
<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/OM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>mil.army.sddc.ibs.ccr</groupId>
  <artifactId>data-mgmt-ws</artifactId>
  <version>1.0</version>
  <packaging>war</packaging>

  <properties>
    <cxf.version>3.0.2</cxf.version>
  </properties>

  <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>generated/cxf</sourceRoot>
              <wsdlOptions>
                <wsdlOption>
                  <wsdl>src/main/resources/dataMgmt.wsdl</wsdl>
                  <serviceName>DataMgmtService</serviceName>
                </wsdlOption>
              </wsdlOptions>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

这是我的 WSDL:

<?xml version="1.0"?>

<wsdl:definitions name="DataMgmtService"
       targetNamespace="http://ccr.ibs.sddc.army.mil/DataMgmt.wsdl"
       xmlns="http://schemas.xmlsoap.org/wsdl/"
       xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
       xmlns:tns="http://ccr.ibs.sddc.army.mil/DataMgmt.wsdl"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

  <message name="SayHelloRequest">
    <part name="firstName" type="xsd:string"/>
  </message>
  <message name="SayHelloResponse">
    <part name="greeting" type="xsd:string"/>
  </message>

  <portType name="DataMgmt_PortType">
    <operation name="sayHelloWorld">
      <input message="tns:SayHelloRequest"/>
      <output message="tns:SayHelloResponse"/>
    </operation>
  </portType>

  <binding name="DataMgmt_Binding" type="tns:DataMgmt_PortType">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="sayHelloWorld">
      <soap:operation soapAction="sayHelloWorld"/>
      <input>
        <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding"
                   namespace="mil.army.sddc.ibs.ccr.DataMgmtWebService"
                   use="encoded"/>
      </input>
      <output>
        <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding"
                   namespace="mil.army.sddc.ibs.ccr.DataMgmtWebService"
                   use="encoded"/>
      </output>
    </operation>
  </binding>

  <service name="DataMgmt_Service">
    <port binding="tns:DataMgmt_Binding" name="DataMgmt_Port">
      <soap:address location="http://ccr.ibs.sddc.army.mil/SayHelloWorld"/>
    </port>
  </service>

</wsdl:definitions>

【问题讨论】:

    标签: web-services maven wsdl cxf wsdl2java


    【解决方案1】:

    在您的cxf-codegen-plugin 配置中,您忘记指定目标wsdl2java。因此,插件的执行不会被调用。

    正确的配置:

    <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> <!-- goal this execution is bound to -->
          </goals>
          <configuration>
            <sourceRoot>generated/cxf</sourceRoot>
            <wsdlOptions>
              <wsdlOption>
                <wsdl>src/main/resources/dataMgmt.wsdl</wsdl>
                <serviceName>DataMgmtService</serviceName>
              </wsdlOption>
            </wsdlOptions>
          </configuration>
        </execution>
      </executions>
    </plugin>
    

    【讨论】:

    • 做到了。我只需要添加 Woodstox 依赖项就可以生成代码了。
    【解决方案2】:

    我尝试运行mvn clean install,代码生成成功

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-27
      • 2014-07-12
      • 2021-10-10
      • 1970-01-01
      • 1970-01-01
      • 2020-12-02
      • 1970-01-01
      • 2017-04-15
      相关资源
      最近更新 更多