Java 如何从包含另一个XSD的XSD生成类
我有两个项目:Java 如何从包含另一个XSD的XSD生成类,java,jaxb,xsd,maven-jaxb2-plugin,Java,Jaxb,Xsd,Maven Jaxb2 Plugin,我有两个项目: xsdproject/ src/main/resources/ a.xsd b.xsd implproject/ 在implproject中,我想使用maven-jaxb2-plugin从xsd生成类 <plugin> <groupId>org.jvnet.jaxb2.maven2</groupId> <artifactId>maven
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>
org.jvnet.jaxb2.maven2
maven-jaxb2-plugin
生成
真的
真的
一些
XSD项目
${project.version}
a、 xsd
一些
XSD项目
${project.version}
b、 xsd
问题出现在这里->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>.
无法读取架构文档“a.xsd”,因为1)找不到该文档;2) 文件无法读取;3) 文档的根元素不是。
有没有办法成功地导入2个XSD并编译它们?免责声明。我是这篇文章的作者 请尝试以下操作:
src/main/resources/catalog.cat
:
REWRITE_SYSTEM "a.xsd" "maven:some.group:xsdproject:jar::!/a.xsd"
在pom.xml中的配置中
<catalog>src/main/resource/catalog.cat</catalog>
src/main/resource/catalog.cat
(见附件。)
我还认为您只需要编译b.xsd
a.xsd
应自动包括在内
如果出现问题,请运行mvn-X clean install
并检查日志
另见:
- -这个项目做的或多或少是相同的事情。该模块仅打包模式,其他模块(例如)从包中编译这些模式。这在任何情况下都适用于导入和包含
如果您需要进一步的支持,请提供一个示例项目。以下内容将有所帮助: