如何使用Apache CXF Maven插件链接到XSD文件?

时间:2014-04-30 14:52:49

标签: java maven wsdl cxf cxf-codegen-plugin

我正在使用Apache cxf-codegen-plugin Maven插件尝试从WSDL文件生成Java类。我收到以下错误:

  

Part <parameters> in Message <{http://www.foo.com/bar}PushCommandSoapIn> referenced Type <{http://www.foo.com/bar}CommandMessage> can not be found in the schemas

有问题的类型(CommandMessage)是在我尝试使用以下POM文件引用的XSD文件中定义的:

<plugin>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-codegen-plugin</artifactId>
  <version>2.7.11</version>
  <executions>
    <execution>
      <id>generate-sources</id>
      <phase>generate-sources</phase>
      <configuration>
        <wsdlOptions>
          <wsdlOption>
            <wsdl>${basedir}/src/main/resources/wsdl/SomeService.wsdl</wsdl>
            <dependencies>
              <!-- Here I try to reference the XSD -->
              <dependency>${basedir}/src/main/resources/wsdl/SomeTypes.xsd</dependency>
            </dependencies>
          </wsdlOption>
        </wsdlOptions>
      </configuration>
      <goals>
        <goal>wsdl2java</goal>
      </goals>
    </execution>
  </executions>
</plugin>  

为什么我收到错误的任何建议?我不确定添加<dependency>是否正确,但我很难找到描述如何引用XSD文件的文档。

以下是WSDL文件中引用缺失类型的片段:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
      xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
      xmlns:bar="http://www.foo.com/bar" 
      targetNamespace="http://www.foo.com/bar">
  <wsdl:message name="PushCommandSoapIn">
    <wsdl:part name="parameters" element="bar:CommandMessage" />
  </wsdl:message>

以下是XSD文件中的标题和摘录:

<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://www.foo.com/bar" 
      xmlns:bar="http://www.foo.com/bar" 
      xmlns="http://www.w3.org/2001/XMLSchema" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema" 
      xmlns:ds="http://www.w3.org/2000/09/xmldsig#" 
      elementFormDefault="qualified" attributeFormDefault="unqualified">
  <import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd" />
  ...
  <element name="CommandMessage" type="bar:CommandMessageType" substitutionGroup="bar:Message" final="#all" />

1 个答案:

答案 0 :(得分:2)

你的wsdl需要一个wsdl:types元素,它有一个带有导入的模式。基本上,wsdl需要了解架构。

 <wsdl:types>
    <xsd:schema>
        <xsd:import namespace="http://www.foo.com/bar" schemaLocation="bar.xsd"/>
    </xsd:schema>
</wsdl:types>