2014-04-30 21 views
1

我正在使用Apache cxf-codegen-plugin Maven插件嘗試從WSDL文件生成Java類。我得到以下錯誤:如何使用Apache CXF Maven插件鏈接到XSD文件?

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" /> 

回答

2

您的WSDL需要一個wsdl:types中的元素,其中包含一個導入模式。基本上,wsdl需要了解模式。

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

謝謝,這似乎解決了這個問題。有沒有辦法在插件中配置它,而不是調整WSDL文件? –

+1

讓WSDL包含XSD文件的硬編碼路徑似乎是錯誤的。這應該是一個構建配置問題。 –

相關問題