0

I have 2 schemas: a.xsd and b.xsd which has a dependency on a.xsd (episode).

Schemas are split in different maven projects and packages.

Originally, b.xsd imports a.xsd like this (I don't want to change it):

<import namespace="urn:a" schemaLocation="a.xsd"/>

What do I need to put in my catalog.cat to translate a.xsd to maven:com.mycompany:a:jar::!/com/mycompany/a/a.xsd

I tried PUBLIC, SYSTEM, URI, REWRITE_URI, REWRITE_SYSTEM but nothing is working.

As soon as I change the reference a.xsd to http://.../a.xsd in my schema and use REWRITE_SYSTEM in my catalog, then it is working. But as I said, I don't want to modify my schema.

Xavier Dury
  • 1,530
  • 1
  • 16
  • 23

2 Answers2

1

Nevermind, it seems to work with SYSTEM_SUFFIX.

Xavier Dury
  • 1,530
  • 1
  • 16
  • 23
0

See Modular Schema Compilation, starting with

However there's a bug in JAXB/XJC this does not work if you have schemaLocation in your xs:import.

Resolving schemas in XJC is quite buggy and I did not see any progress on that in the last few years.

So what works for me quite well in a number of projects:

Compile you schemas not from the local path but some absolute URL. This does not need to actually exist, can be completely virtual. Just use an absolute 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>

Use a catalog file to rewrite your absolute URL prefix to some local path or resource in a JAR:

REWRITE_SYSTEM "http://schemas.opengis.net" "maven:org.jvnet.ogc:ogc-schemas:jar::!/ogc"

Apply your bindings not to local files but via absolute 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>

Thus all your URLs will be absolute (without the need to patch the schemas) and so REWRITE_SYSTEM will work as desired. This is the best option I've found so far, and, believe me, I've compiled a lot of schemas.

Disclaimer: I'm the author of maven-jaxb2-plugin.

lexicore
  • 42,748
  • 17
  • 132
  • 221
  • On the page [Modular Schema Compilation](https://github.com/highsource/maven-jaxb2-plugin/wiki/Modular-Schema-Compilation), the link to the Oracle pull request doesn't work, can you fix it please so we can see the status. – Chaithu Narayana Dec 05 '17 at 12:19
  • In the meanwhile. somehow using SYSTEM_SUFFIX in my catalog file as described in the above answer, resolves my issue. I was able to compile and generate sources for project B in your example. In our case, we get the contracts from a 3rd party who includes project A.xsd inside B.xsd as below, and unfortunately, I cannot change it. ` ` Just curious to know if this is OK to use as you haven't recommended using this option in any of your answers? – Chaithu Narayana Dec 05 '17 at 12:20