cxf-codegen-plugin 不生成代码

cxf-codegen-plugin not generating code

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

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