5

I want to add an xsd file to our project that relies on types defined in another xsd that is in a jar. We use jaxb to generate Java classes from the xsds. How do i refer to SchemaContainingFooTypeIsInaJAR.xsd so that 'FooType' resolves correctly and the proper Java classes get generated

<?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>
charudatta
  • 409
  • 1
  • 7
  • 15

3 Answers3

2

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:

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.

lexicore
  • 42,748
  • 17
  • 132
  • 221
  • Great stuff. In the second document, the link under "See this section in the JAXB guide" is broken. – Geoffrey De Smet Jan 30 '13 at 12:43
  • 1
    @GeoffreyDeSmet Thanks, fixed. Here's this link: http://jaxb.java.net/guide/Fixing_broken_references_in_schema.html – lexicore Jan 30 '13 at 19:04
  • current link is https://javaee.github.io/jaxb-v2/doc/user-guide/ch03.html#compiling-xml-schema-fixing-broken-references-in-schema – beat Oct 03 '18 at 14:40
0

See XML Schema reference and JAXB SchemaFactory source order must follow import order between schemas?

The consensus appears to be: you need to supply your own resolver.

Community
  • 1
  • 1
C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65
0

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"/>

Everlight
  • 431
  • 5
  • 18