so

XML Catalogs in ZIP files

Volume 7, Issue 21; 04 Mar 2023

Using XML catalogs in ZIP files with a cheeky jar: URI.

The XML Resolver will search the classpath for catalogs.If you ask it to. This means that if you use, for example, the DocBook xslTNG Stylesheets, putting the stylesheet jar file on the classpath and using the resolver is enough to get local resolution for the stylesheets. You don’t have to explicitly configure the catalogs.

This is great, except it doesn’t work when you run the transformation task in Gradle. I suppose this has been true for a while, but I only noticed because a CI job got a random error loading the stylesheets from the CDN and failed. (It shouldn’t have needed to go to the CDN for the stylesheets.)

You can also put a ZIP file on the classpath, but that only works if the catalog is at a known location in the ZIP. The structure of the DocBook xslTNG Stylesheet distribution ZIP doesn’t lend itself to that structure.

I started casting about, wondering if I was going to have to generate another distribution artifact for the stylesheets or add a new option to the XML Resolver to work around this, when it occurred to me that I could probably just cheat.

I tried to load the catalog file with something like this:

jar:file:/path/to/file.zip!/path/to/catalog.xml

And it worked!

It’s kind of cheeky because a ZIP file isn’t a JAR file. However, a JAR file is a ZIP file, so the code that looks for the catalog in the “jar file” works just fine.

Problem solved (mostly; I also had to switch to using URIs for the Saxon inputs in the short term, but that was easy too).

#XML Resolver