cxf-codegen-plugin不生成代码

时间:2015-10-28 04:46:34

标签: 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>

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

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