2014-10-31 42 views
4

類我有2個項目:怎樣才能從XSD包括另一個XSD

xsdproject/ 
    src/main/resources/ 
     a.xsd 
     b.xsd 

implproject/ 

在implproject我要生成使用maven-JAXB2-插件從XSD類。

 <plugin> 
      <groupId>org.jvnet.jaxb2.maven2</groupId> 
      <artifactId>maven-jaxb2-plugin</artifactId> 
      <executions> 
       <execution> 
        <goals> 
         <goal>generate</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <cleanPackageDirectories>true</cleanPackageDirectories> 
       <forceRegenerate>true</forceRegenerate> 
       <schemas> 
        <schema> 
         <dependencyResource> 
          <groupId>some.group</groupId> 
          <artifactId>xsdproject</artifactId> 
          <version>${project.version}</version> 
          <resource>a.xsd</resource> 
         </dependencyResource> 
        </schema> 
        <schema> 
         <dependencyResource> 
          <groupId>some.group</groupId> 
          <artifactId>xsdproject</artifactId> 
          <version>${project.version}</version> 
          <resource>b.xsd</resource> 
         </dependencyResource> 
        </schema> 
       </schemas> 
      </configuration> 
     </plugin> 

,問題就出現在這裏 - > b.xsd有

<xs:include schemaLocation="a.xsd" /> 

和生成過程中我有一個錯誤:

Failed to read schema document 'a.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. 

有沒有辦法來成功地導入2 XSD和編譯他們?

+0

以下內容應該有所幫助:http://blog.bdoughan.com/2011/10/jaxb-xjc-imported-schemas-and-xml.html – 2014-10-31 14:42:29

回答

2

免責聲明。我是maven-jaxb2-plugin的作者。

嘗試以下操作:

src/main/resources/catalog.cat

REWRITE_SYSTEM "a.xsd" "maven:some.group:xsdproject:jar::!/a.xsd" 

configurationpom.xml

<catalog>src/main/resource/catalog.cat</catalog> 

(見Using Catalogs

我還以爲你只需要編譯b.xsd。應自動包含a.xsd

如果出現問題,運行mvn -X clean install並檢查日誌。

參見:

如果您需要進一步的支持,請file an issue並提供一個示例項目。