私は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に適用されているだけです。