2016-08-15 9 views
0

私はXSDファイルからクラスを生成するためにJAXBを使用しています。私は生成されるクラスに共通のインターフェースを実装させたいと思っています。だから、これを行うにはexternal binding fileの方法でJAXB2 Basicsプラグインを試しています。これは私のカスタムバインディングファイルです: 注私で追加したコメント私が行った変更がされていますJAXB2 Basicsプラグイン - 外部バインディングカスタマイズファイルのschemaLocationに関する問題

customBindingFile.xjb

<?xml version="1.0"?> 
<jxb:bindings version="1.0" 
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
    xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance" 
    jxb:extensionBindingPrefixes="xjc"> 

    <jxb:bindings schemaLocation="abc-api.xsd"> 
     <jxb:bindings node="//xs:complexType[@name='MyClass']"> 
     <inheritance:implements>com.kuldeep.CommonInterface</inheritance:implements> 
     </jxb:bindings> 
    </jxb:bindings> 
</jxb:bindings> 

ソース生成のためのPOMファイルで、私のMavenプラグインは次のとおりこの既存のプラグインエントリ。

のpom.xml

<plugin> 
    <groupId>org.apache.cxf</groupId> 
    <artifactId>cxf-codegen-plugin</artifactId> 
    <version>${cxf.plugin.version}</version> 
    <executions> 
    <execution> 
     <id>generate-sources</id> 
     <phase>generate-sources</phase> 
     <configuration> 

     <!-- **extensions and args added by me** --> 
     <extensions> 
      <extension>org.jvnet.jaxb2_commons:jaxb2-basics:0.9.2</extension> 
     </extensions> 
     <args> 
      <arg>-Xinheritance</arg> 
     </args> 


     <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot> 
     <defaultOptions> 
      <bindingFiles> 
      <bindingFile>src/main/resources/jaxws_binding.xml</bindingFile> 
      <bindingFile>src/main/resources/jaxb_binding.xml</bindingFile> 
      </bindingFiles> 
     </defaultOptions> 
     <wsdlOptions> 
      ...... 
      <wsdlOption> 
      <wsdl>${project.build.directory}/generated/framework/cxf/abc-api-inline.wsdl</wsdl> 

      <!-- **bindingFile added by me** --> 
      <bindingFile>src/main/resources/customBindingFile.xjb</bindingFile> 

      </wsdlOption> 
     </wsdlOptions> 
     </configuration> 
     <goals> 
     <goal>wsdl2java</goal> 
     </goals> 
    </execution> 
    </executions> 

    <!-- **dependency added by me** --> 
    <dependencies> 
    <dependency> 
     <groupId>org.jvnet.jaxb2_commons</groupId> 
     <artifactId>jaxb2-basics</artifactId> 
     <version>0.9.2</version> 
    </dependency> 
    </dependencies> 

</plugin> 

私が持っている問題は、私のスキーマファイルであるABC-api.xsdは私がしようとするので、私のクラスを生成するためにMavenをインストールし、いくつかの他のプロジェクトに存在しますabc-api.xsdはこのコンパイルの一部ではないというエラーが表示されます

[ERROR] Failed to execute goal org.apache.cxf:cxf-codegen-plugin:3.0.3:wsdl2java (generate-sources) on project : Execution generate-sources of goal org.apache.cxf:cxf-codegen-plugin:3.0.3:wsdl2java failed: file:/I:/project/src/main/resources/customBindingFile.xjb [9,56]: "file:/I:/project/src/main/resources/abc-api.xsd" is not a part of this compilation. Is this a mistake for "file:/I:/project/src/main/resources/jaxb_binding.xml"? -> [Help 1]

そして、私はそれが動作し、エラーを与えていないcustomBindingFile.xjbからschemaLocation属性を削除する場合:

XPath evaluation of "//xs:complexType[@name='MyClass']" results in empty target node

だから私の質問は、私は/特定のスキーマファイル名を提供する避けることができる方法であります場所はcustomBindingFile.xjbであり、クラスを生成するために使用しているxsdに適用されているだけです。

答えて

0

私たちのアーキテクトの助けを借りて、この問題を解決できました。 jaxwsバインディングファイルを追加し、そこにプレフィックスレスのxpathクエリを使用して、リクエスト要素に一致させました。 この方法では、どこにでもスキーマの場所を指定する必要はなく、XPathクエリに基づいて特定のWSDLに適用されます。

jaxws_binding_inheritance.xml

<jaxws:bindings version="2.0" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
    xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance" jaxb:extensionBindingPrefixes="inheritance xjc" 
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.1"> 

    <jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle> 

    <jaxws:bindings 
    node="*[local-name()='definitions']/*[local-name()='types']/*[local-name()='schema' and 
      (@targetNamespace='urn:net:mycompany:api:abc')]"> 

    <jaxb:bindings 
     node="//*[local-name()='element' and 
      not(@name = 'ExcludeThisRequest' or @name = 'AlsoExcludeThisRequest') and 
      (substring(@name, string-length(@name) - string-length('Request') +1) = 'Request')]/*[local-name()='complexType']"> 
     <inheritance:implements>com.kuldeep.CommonRequest</inheritance:implements> 
    </jaxb:bindings> 

    </jaxws:bindings> 
</jaxws:bindings> 

そしてJAXWSが、私はそれを適用したいWSDLのwsdloption下のファイル(jaxws_binding_inheritance.xml)を結合することを付け加えました。

のpom.xml

<wsdlOption> 
    <wsdl>${project.build.directory}/generated/framework/cxf/abc-api-inline.wsdl</wsdl> 
    <bindingFiles> 
    <bindingFile>src/main/resources/jaxws_binding_inheritance.xml</bindingFile> 
    </bindingFiles> 
</wsdlOption> 
関連する問題