2015-07-20 151 views
1

我正在嘗試更改從wsdl生成的類的名稱(我不想直接修改任何wsdl或xsd文件)。問題是它的定義是在一個單獨的xsd文件中。JAXWS:如何更改在外部XSD中定義的CXF生成的類名稱?

WSDL的結構基金看起來是這樣的:

main.wsdl:

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://foo.bar/zee"> 
<wsdl:import location="typedef.wsdl" namespace="http://foo.bar/wee"> 
</wsdl:import> 
    ... 
</wsdl:definitions> 

typedef.wsdl:

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Foo" targetNamespace="http://foo.bar/wee"> 
    <wsdl:types> 
     <xsd:schema> 
      <xsd:import namespace="http://foo.bar/wee/schema" schemaLocation="FooBar.xsd"/> 
     </xsd:schema> 
    </wsdl:types> 
    ... 
<wsdl:definitions> 

FooBar.xsd:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://foo.bar/wee/schema"> 
    ... 
    <xsd:complexType name="FooType"> 
    <xsd:sequence> 
     ... 
    </xsd:complexType> 
</xsd:schema>  

現在假設我想重命名F oooType類到Foo。閱讀後:JAXB: How to change XJC-generated classes names when attr type is specified in XSD?我已經創建了以下綁定文件。

jaxws_bindings.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<jxb:bindings 
     xmlns:xs="http://www.w3.org/2001/XMLSchema" 
     xmlns:jxb="http://java.sun.com/xml/ns/jaxb" 
     version="2.1" 
     wsdlLocation="http://127.0.0.1:8431/Foo/types.wsdl"> 

    <jxb:bindings schemaLocation="http://127.0.0.1:8431/Foo/FooBar.xsd"> 
     <jxb:bindings node="//xs:complexType[@name='FooType']"> 
      <jxb:class name="Foo"/> 
     </jxb:bindings> 
    </jxb:bindings> 

</jxb:bindings> 

但我得到的是一個錯誤:

[ERROR] Failed to execute goal org.apache.cxf:cxf-codegen-plugin:2.7.0:wsdl2java (generate-sources) on 
project foo: Execution generate-sources of goal org.apache.cxf:cxf-codegen-plugin:2.7.0:wsdl2java failed: 
file:/E:/sources/.../jaxws_bindings.xml [8,95]: "http://127.0.0.1:8431/Foo/FooBar.xsd" is not a part of 
this compilation. Is this a mistake for "http://127.0.0.1:8431/Foo/FooBar.xsd"? -> [Help 1] 

我已經嘗試了一切,來到我的腦海裏,但仍然沒有什麼接近成功。 任何人都碰巧知道如何做到這一點?

PS:爲了生成我用maven CXF代碼生成插件與pom.xml的一個下面的配置的類:

<build> 
    <finalName>${project.groupId}.${project.artifactId}</finalName> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.cxf</groupId> 
     <artifactId>cxf-codegen-plugin</artifactId> 
     <version>2.7.0</version> 
     <executions> 
      <execution> 
      <id>generate-sources</id> 
      <phase>generate-sources</phase> 
      <configuration> 
       <sourceRoot>${project.build.directory}/generated-sources</sourceRoot> 
       <wsdlOptions> 
       <wsdlOption> 
        <wsdl>http://127.0.0.1:8431/Foo/main.wsdl</wsdl> 
        <extraargs> 
        <extraarg>-client</extraarg> 
        </extraargs> 
        <bindingFiles> 
        <bindingFile>jaxws_bindings.xml</bindingFile> 
        </bindingFiles> 
       </wsdlOption> 
       </wsdlOptions> 
      </configuration> 
      <goals> 
       <goal>wsdl2java</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
</build> 

回答

1

我這出根據this gist

雖然這個作品與XJC:

<jaxb:bindings 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
    version="1.0"> 
    <jaxb:bindings schemaLocation="..." 
       node="/xsd:schema/xsd:element[@name='Bar']"> 
    <jaxb:class name="Foo"/> 
    </jaxb:bindings> 
</jaxb:bindings> 

你需要這個與CXF:

<jaxb:bindings 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
    version="1.0"> 
    <jaxb:bindings schemaLocation="..." 
       node="/xsd:schema/xsd:complexType[@name='Case']"> 
    <jaxb:class name="Wat" implClass="bar"/> 
    </jaxb:bindings> 
</jaxb:bindings> 

不同的是element VS complexType