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.