簡體   English   中英

如何從包含其他XSD的XSD生成類

[英]How can I generate classes from XSD that includes another XSD

我有2個項目:

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

implproject/

在implproject中,我想使用maven-jaxb2-plugin從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並編譯它們?

免責聲明。 我是maven-jaxb2-plugin

請嘗試以下方法:

src/main/resources/catalog.cat

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

pom.xmlconfiguration

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

(請參閱使用目錄 。)

我還認為你只需要編譯b.xsd 應自動包含a.xsd

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

也可以看看:

如果您需要進一步的支持,請提交問題並提供示例項目。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM