简体   繁体   English

在jar中引用/包含xsd文件

[英]referencing/including xsd files in a jar

I want to add an xsd file to our project that relies on types defined in another xsd that is in a jar. 我想在我们的项目中添加一个xsd文件,该文件依赖于jar中另一个xsd中定义的类型。 We use jaxb to generate Java classes from the xsds. 我们使用jaxb从xsds生成Java类。 How do i refer to SchemaContainingFooTypeIsInaJAR.xsd so that 'FooType' resolves correctly and the proper Java classes get generated 我如何引用SchemaContainingFooTypeIsInaJAR.xsd以便'FooType'正确解析并生成正确的Java类

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="SchemaContainingFooTypeIsInaJAR.xsd"/>
<xs:complexType name="FooMoreType">
    <xs:complexContent>
        <xs:extension base="FooType">
            <xs:sequence>
                <xs:element name="something" type="xs:boolean" minOccurs="0">
                    <xs:annotation>
                        <xs:documentation xml:lang="en">
                            something something
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>
</xs:schema>

You might be interested in these features: 您可能对以下功能感兴趣:

In short, you can write a catalog file which would point to your schema in a JAR file: 简而言之,您可以编写一个目录文件,该文件将指向JAR文件中的架构:

REWRITE_SYSTEM "some/url/a.xsd" "maven:org.jvnet.jaxb2.maven2:maven-jaxb2-plugin-tests-episodes-a!/a.xsd"

DISCLAIMER: I am the principal dev of maven-jaxb2-plugin. 免责声明:我是maven-jaxb2-plugin的主要开发者。

See XML Schema reference and JAXB SchemaFactory source order must follow import order between schemas? 请参阅XML Schema参考JAXB SchemaFactory源顺序必须遵循模式之间的导入顺序?

The consensus appears to be: you need to supply your own resolver. 共识似乎是:您需要提供自己的解析器。

Replace your line: 替换你的行:

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

with

<xs:include schemaLocation="jar:file:///path/to/jar/thing.jar!/path/inside/jar/to/file.xsd"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM