如何从XSD生成包含另一个XSD的类?

4

我有两个项目:

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>.

有没有一种成功导入两个XSD并编译它们的方法?

以下内容应该会有所帮助:http://blog.bdoughan.com/2011/10/jaxb-xjc-imported-schemas-and-xml.html - bdoughan
1个回答

2

免责声明。我是maven-jaxb2-plugin的作者。

请尝试以下操作:

src/main/resources/catalog.cat

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

pom.xml 中的 configuration 中。
<catalog>src/main/resource/catalog.cat</catalog>

(参见使用目录。)
我认为您只需要编译b.xsda.xsd会自动包含在内。
如果出现问题,请运行mvn -X clean install并检查日志。
另请参阅: 如果需要进一步支持,请提交问题并提供示例项目。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接