Relative paths in XML catalogs are treated differently on windows and linux using XJC

3.1k views Asked by At

We use XJC version "JAXB 2.1.10 in JDK 6" (by using jaxb2-maven-plugin) to generate JAXB classes based on OGC's WFS 2.0. We use a catalog file for resolving schemas the WFS schema depends on. The entries in the catalog file reference schemas on the file system by using relative paths, e.g.

<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">

    <rewriteSystem
        systemIdStartString="http://www.w3.org/2001/"
        rewritePrefix="../../2001/"/>

    <rewriteSystem
        systemIdStartString="http://www.w3.org/1999/"
        rewritePrefix="../../w3c/"/>

    <rewriteSystem
        systemIdStartString="http://schemas.opengis.net/ows/1.1/"
        rewritePrefix="../../ows/1.1.0/"/>

    <rewriteSystem
        systemIdStartString="http://schemas.opengis.net/ows/1.1.0/"
        rewritePrefix="../../ows/1.1.0/"/>

    <rewriteSystem
        systemIdStartString="http://schemas.opengis.net/filter/2.0/"
        rewritePrefix="../../filter/2.0/"/>

</catalog>

This is working fine on linux, but on windows, we get a java.io.FileNotFoundException for each file defined in the catalog. It makes no difference whether XJC is called by the maven plugin or directly, the behaviour is the same. In fact, we didn't manage to make XJC work on windows using relative paths in the catalog at all.

Excerpt of the log running mvn -X clean install:

+ Error stacktraces are turned on.
Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
Java version: 1.6.0_20
Java home: C:\Program Files\Java\jdk1.6.0_20\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows"
[DEBUG] Configuring mojo 'org.codehaus.mojo:jaxb2-maven-plugin:1.5:xjc' -->
[DEBUG]   (f) bindingDirectory = C:\dev\depot\myproject\src\main\xsd\wfs\2.0
[DEBUG]   (f) catalog = C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.cat
[DEBUG]   (f) clearOutputDir = false
[DEBUG]   (f) dtd = false
[DEBUG]   (f) enableIntrospection = false
[DEBUG]   (f) encoding = UTF-8
[DEBUG]   (f) explicitAnnotation = false
[DEBUG]   (f) extension = false
[DEBUG]   (f) failOnNoSchemas = true
[DEBUG]   (f) npa = false
[DEBUG]   (f) nv = false
[DEBUG]   (f) outputDirectory = C:\dev\depot\myproject\target\generated-sources\jaxb
[DEBUG]   (f) project = MavenProject: com.myproject:MyProject:1.0.0-SNAPSHOT @ C:\dev\depot\myproject\pom.xml
[DEBUG]   (f) quiet = false
[DEBUG]   (f) readOnly = false
[DEBUG]   (f) relaxng = false
[DEBUG]   (f) relaxngCompact = false
[DEBUG]   (f) schemaDirectory = C:\dev\depot\myproject\src\main\xsd\wfs\2.0
[DEBUG]   (f) staleFile = C:\dev\depot\myproject\target\stale\wfs\2.0
[DEBUG]   (f) verbose = false
[DEBUG]   (f) wsdl = false
[DEBUG]   (f) xmlschema = true
[DEBUG] -- end configuration --
[INFO] [jaxb2:xjc {execution: wfs}]
[DEBUG] Using XJC of JAXB Reference Implementation  version 2.1.13
[DEBUG] The schema Directory is C:\dev\depot\myproject\src\main\xsd\wfs\2.0
[DEBUG] accept false for file C:\dev\depot\myproject\src\main\xsd\wfs\2.0\CVS
[DEBUG] accept false for file C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.cat
[DEBUG] accept false for file C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.xjb
[DEBUG] accept true for file C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.xsd
[DEBUG] The binding Directory is C:\dev\depot\myproject\src\main\xsd\wfs\2.0
[INFO] Generating source...
[DEBUG] C:\dev\depot\myproject\target\classes
[DEBUG] D:\mvnrep\commons-codec\commons-codec\1.3\commons-codec-1.3.jar
[DEBUG] D:\mvnrep\commons-lang\commons-lang\2.6\commons-lang-2.6.jar
[DEBUG] D:\mvnrep\org\apache\httpcomponents\httpclient\4.1.2\httpclient-4.1.2.jar
[DEBUG] D:\mvnrep\org\apache\httpcomponents\httpcore\4.1.2\httpcore-4.1.2.jar
[DEBUG] D:\mvnrep\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar
[DEBUG] The binding Directory is C:\dev\depot\myproject\src\main\xsd\wfs\2.0
[DEBUG] accept false for file C:\dev\depot\myproject\src\main\xsd\wfs\2.0\CVS
[DEBUG] accept false for file C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.cat
[DEBUG] accept false for file C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.xjb
[DEBUG] accept true for file C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.xsd
[DEBUG] JAXB XJC args: [-xmlschema, -catalog, C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.cat, -d, C:\dev\depot\myproject\target\generated-sources\jaxb, -classpath, C:\dev\depot\myproject\target\classes;D:\mvnrep\commons-codec\commons-codec\1.3\commons-codec-1.3.jar;D:\mvnrep\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\mvnrep\org\apache\httpcomponents\httpclient\4.1.2\httpclient-4.1.2.jar;D:\mvnrep\org\apache\httpcomponents\httpcore\4.1.2\httpcore-4.1.2.jar;D:\mvnrep\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar;, -b, C:\dev\depot\myproject\src\main\xsd\wfs\2.0\wfs.xjb, C:\dev\depot\myproject\src\main\xsd\wfs\2.0]
[INFO] parsing a schema...
[ERROR] null[-1,-1]
java.io.FileNotFoundException: C:\dev\depot\myproject\owsGetResourceByID.xsd (Das System kann die angegebene Datei nicht finden)
    at com.sun.tools.xjc.ErrorReceiver.error(ErrorReceiver.java:90)
    at com.sun.tools.xjc.reader.internalizer.DOMForest.parse(DOMForest.java:401)
    at com.sun.tools.xjc.reader.internalizer.DOMForest.parse(DOMForest.java:300)
    at com.sun.tools.xjc.reader.internalizer.AbstractReferenceFinderImpl.startElement(AbstractReferenceFinderImpl.java:95)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
    at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:179)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:377)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    at com.sun.tools.xjc.reader.internalizer.DOMForest.parse(DOMForest.java:393)
    at com.sun.tools.xjc.reader.internalizer.DOMForest.parse(DOMForest.java:300)
    at com.sun.tools.xjc.reader.internalizer.AbstractReferenceFinderImpl.startElement(AbstractReferenceFinderImpl.java:95)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
    at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:179)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:377)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    at com.sun.tools.xjc.reader.internalizer.DOMForest.parse(DOMForest.java:393)
    at com.sun.tools.xjc.reader.internalizer.DOMForest.parse(DOMForest.java:273)
    at com.sun.tools.xjc.ModelLoader.buildDOMForest(ModelLoader.java:321)
    at com.sun.tools.xjc.ModelLoader.loadXMLSchema(ModelLoader.java:374)
    at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:167)
    at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:113)
    at com.sun.tools.xjc.Driver.run(Driver.java:313)
    at org.codehaus.mojo.jaxb2.AbstractXjcMojo.execute(AbstractXjcMojo.java:327)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
...
[INFO] Failed to parse a schema.
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Could not process schema files in directory C:\dev\depot\myproject\src\main\xsd\wfs\2.0
[INFO] ------------------------------------------------------------------------
[DEBUG] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Could not process schema files in directory C:\dev\depot\myproject\src\main\xsd\wfs\2.0
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Could not process schema files in directory C:\dev\depot\myproject\src\main\xsd\wfs\2.0
    at org.codehaus.mojo.jaxb2.AbstractXjcMojo.execute(AbstractXjcMojo.java:343)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    ... 17 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Tue Nov 11 06:56:54 CET 2014
[INFO] Final Memory: 25M/181M
[INFO] ------------------------------------------------------------------------

Did somebody face similar problems and was able to find a solution?

Note:
- Using absolute paths is not a solution as we want it to work on both linux and windows
- Using a newer version of XJC/JAXB is not an option at the moment
- Using the "OGC Schemas and Tools Project" is not an option as we want full control of the generation process and the classes for the WFS schema are just a side product of the generation of classes for custom schemas. Generating classes for WFS is just an example.

1

There are 1 answers

6
lexicore On

When reporting this kind of things, always post mvn -X install. Logs and stack traces tell a lot. My , for instance, logs (among others) debug info from the catalog resolver, so you'd see something like:

resolveSystem(file:/C:/Projects/workspaces/mj2p/maven-jaxb2-plugin-project/tests/gh-issue-16/src/main/resources/ab/a.xsd)
resolveSystem(file:/C:/Projects/workspaces/mj2p/maven-jaxb2-plugin-project/tests/gh-issue-16/src/main/resources/ab/a.xsd)
resolveSystem(http://www.ab.org/b.xsd)
Resolved system: http://www.ab.org/b.xsd
    file:/C:/Projects/workspaces/mj2p/maven-jaxb2-plugin-project/tests/gh-issue-16/src/main/resources/ab/b.xsd
resolveSystem(http://www.ab.org/b.xsd)

I've just put up a small test project to test it, so I can actually confirm that relative paths in catalogs do work. At least with and JAXB 2.2.11. This is the catalog file I used:

REWRITE_SYSTEM "http://www.ab.org" "../ab"

Important note: files are resolved relatively to the catalog file itself. I have put the catalog file under src/main/resources/ab/catalog.cat and http://www.ab.org/b.xsd got resolved to src/main/resources/ab/b.xsd.

And finally, have you seen the ogc-schemas project on GitHub? It is the continuation of my old OGC Schemas and Tools project, it compiles OGC Schemas with JAXB XJC. The WFS schema you need is already compiled there, you can either use the artifact or compile it on your own using the provided binding files.

By the way, how I hande compilation in the ogc-schemas project:

  • I first package all the schemas in a separate artifact.
  • I define a catalog file with a rewriting rule to rewrite all the http://schemas.opengis.net/... URLs to that Maven artifact:

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

I think your problem is that URLs are resolved relatively but relatively to the catalog file and this is probably not what you expect.

Disclaimer: I am the author of the and the ogc-schemas project mentioned above.