web-services - cxf-codegen-plugin 不生成代码

标签 web-services maven wsdl cxf wsdl2java

我正在尝试使用 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>

最佳答案

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>

关于web-services - cxf-codegen-plugin 不生成代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33383091/

相关文章:

c# - 使用 Web 服务响应

c# - 从 LINQ 查询结果集中填充 DataSet 或 DataTable

java - NoSuchMethodError 因为找到了错误的类

java - 使用 lombok API 时 Eclipse 显示编译错误消息

java - Maven proguard-maven-plugin 重复的类定义和错误命名的文件

java - 是否可以生成填充了安全 header 的 WSDL?

Java 使用 Web 服务

android - 如何在Android中按其内容存储和搜索mp3

javax.xml.ws.WebServiceException : Method X is exposed as WebMethod, 但是没有对应的wsdl操作

php - 如何制作 PHP SOAP 客户端并将结果 xml 存储在 php 变量中