当 location 不是 URL 时,使用模块化 JAXB 编译不起作用(似乎)
Using modular JAXB compilation does not (seem to) work when location is not an URL
我有 2 个模式:a.xsd
和 b.xsd
,它们依赖于 a.xsd
(剧集)。
模式拆分在不同的 Maven 项目和包中。
最初,b.xsd
导入 a.xsd
是这样的(我不想更改它):
<import namespace="urn:a" schemaLocation="a.xsd"/>
我需要在 catalog.cat
中输入什么才能将 a.xsd
翻译成 maven:com.mycompany:a:jar::!/com/mycompany/a/a.xsd
我尝试了 PUBLIC、SYSTEM、URI、REWRITE_URI、REWRITE_SYSTEM,但没有任何效果。
只要我将架构中的引用 a.xsd
更改为 http://.../a.xsd
并在我的目录中使用 REWRITE_SYSTEM,它就会正常工作。但正如我所说,我不想修改我的架构。
没关系,它似乎适用于 SYSTEM_SUFFIX。
参见 Modular Schema Compilation,从
开始
However there's a bug in JAXB/XJC this does not work if you have schemaLocation in your xs:import
.
在 XJC 中解决模式问题很多,过去几年我没有看到任何进展。
中什么对我很有效
不是从本地路径而是从一些绝对路径编译模式 URL。这个不需要实际存在,完全可以是虚拟的。只需使用绝对 URL:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<schemas>
<schema>
<url>http://schemas.opengis.net/ows/2.0/owsAll.xsd</url>
</schema>
</schemas>
<!-- ... -->
</configuration>
</plugin>
使用目录文件将绝对 URL 前缀重写为 JAR 中的某个本地路径或资源:
REWRITE_SYSTEM "http://schemas.opengis.net" "maven:org.jvnet.ogc:ogc-schemas:jar::!/ogc"
不将绑定应用到本地文件,而是通过绝对 URLs:
<jaxb:bindings schemaLocation="http://schemas.opengis.net/ows/2.0/owsAll.xsd" node="/xs:schema">
<jaxb:schemaBindings>
<jaxb:package name="net.opengis.ows.v_2_0"/>
</jaxb:schemaBindings>
</jaxb:bindings>
因此您所有的 URL 都将是绝对的(无需修补模式),因此 REWRITE_SYSTEM
将按需要工作。这是迄今为止我找到的最佳选择,相信我,我已经编译了很多模式。
免责声明:我是maven-jaxb2-plugin的作者。
我有 2 个模式:a.xsd
和 b.xsd
,它们依赖于 a.xsd
(剧集)。
模式拆分在不同的 Maven 项目和包中。
最初,b.xsd
导入 a.xsd
是这样的(我不想更改它):
<import namespace="urn:a" schemaLocation="a.xsd"/>
我需要在 catalog.cat
中输入什么才能将 a.xsd
翻译成 maven:com.mycompany:a:jar::!/com/mycompany/a/a.xsd
我尝试了 PUBLIC、SYSTEM、URI、REWRITE_URI、REWRITE_SYSTEM,但没有任何效果。
只要我将架构中的引用 a.xsd
更改为 http://.../a.xsd
并在我的目录中使用 REWRITE_SYSTEM,它就会正常工作。但正如我所说,我不想修改我的架构。
没关系,它似乎适用于 SYSTEM_SUFFIX。
参见 Modular Schema Compilation,从
开始However there's a bug in JAXB/XJC this does not work if you have schemaLocation in your
xs:import
.
在 XJC 中解决模式问题很多,过去几年我没有看到任何进展。
中什么对我很有效不是从本地路径而是从一些绝对路径编译模式 URL。这个不需要实际存在,完全可以是虚拟的。只需使用绝对 URL:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<schemas>
<schema>
<url>http://schemas.opengis.net/ows/2.0/owsAll.xsd</url>
</schema>
</schemas>
<!-- ... -->
</configuration>
</plugin>
使用目录文件将绝对 URL 前缀重写为 JAR 中的某个本地路径或资源:
REWRITE_SYSTEM "http://schemas.opengis.net" "maven:org.jvnet.ogc:ogc-schemas:jar::!/ogc"
不将绑定应用到本地文件,而是通过绝对 URLs:
<jaxb:bindings schemaLocation="http://schemas.opengis.net/ows/2.0/owsAll.xsd" node="/xs:schema">
<jaxb:schemaBindings>
<jaxb:package name="net.opengis.ows.v_2_0"/>
</jaxb:schemaBindings>
</jaxb:bindings>
因此您所有的 URL 都将是绝对的(无需修补模式),因此 REWRITE_SYSTEM
将按需要工作。这是迄今为止我找到的最佳选择,相信我,我已经编译了很多模式。
免责声明:我是maven-jaxb2-plugin的作者。