1
votes

I have some XSD where some share common definitions. I separated this common definitions into a separate XSD. So far I imported this common.xsd via relative paths across the projects. Thsi worked because all projects kived in the dame SCM repository.

Now I separate the projects into separate SCM repositories and I need to change the access to the common.xsd whch already lives in its own project (common-xml.jar).

I read tis: http://www.sagehill.net/docbookxsl/WriteCatalog.html and https://github.com/highsource/maven-jaxb2-plugin/wiki/Using-Catalogs but it does not work or me. The catalog is not used and xjc looks up the common.xsd in the path configuret in maven-jaxb2-plugin/configuration/schemaDirectory.

Even if I add maven-jaxb2-plugin/configuration/arg>-Dxml.catalog.verbosity=999 (or run mvn -X -Dxml.catalog.verbosity=999 ... it does not even tell to read the catalog file.

I only get output for the catalog file when I use the XML form and keep the <!DOCTYPE ..:> element, but this leads to a timeout since the proxy does only allow browsers to connect to the internet (corporate policy).

I also read this answer Maven - Have an XSD as a dependency but it results in the same problem: xjc looks in the schema directory for the file to include but I want to avoid to extract it to a place where it might by checked in into the SCM accidentally...

How do I force xjc to lookup the location for the XSD to import somewere else?

this is my maven project configuration:

   <plugin>
      <groupId>org.jvnet.jaxb2.maven2</groupId>
      <artifactId>maven-jaxb2-plugin</artifactId>
      <version>0.14.0</version>
      <configuration>
        <args>-Dxml.catalog.verbosity=999</args>
        <clearOutputDir>true</clearOutputDir>
        <removeOldOutput>true</removeOldOutput>
        <specVersion>2.2</specVersion>
        <arguments>-Xcommons-lang</arguments>
        <schemaDirectory>../src/main/xsd</schemaDirectory>
        <catalogs>
          <catalog>
            <dependencyResource>
              <groupId>my.group.id</groupId>
              <artifactId>common-xml-definitions</artifactId>
              <resource>catalog.xml</resource> 
             <!-- alternatively 
              <resource>catalog.cat</resource>
             for plain text version -->;
            </dependencyResource>
          </catalog>
        </catalogs>
        <schemaIncludes>
          <schemaInclude>*.xsd</schemaInclude>
        </schemaIncludes>
        <bindingDirectory>../src/main/xjb</bindingDirectory>
        <bindingIncludes>
          <bindingInclude>bindings.xml</bindingInclude>
        </bindingIncludes>
        <schemaLanguage>XMLSCHEMA</schemaLanguage>
        <generatePackage>a.package.name</generatePackage>
        <verbose>false</verbose>
        <args>
          <arg>-XtoString</arg>
          <arg>-Xequals</arg>
          <arg>-XhashCode</arg>
        </args>
        <plugins>
          <plugin>
            <groupId>com.buschmais.jaxbfx</groupId>
            <artifactId>jaxbfx-plugin</artifactId>
            <version>1.1.0</version>
          </plugin>
          <plugin>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>jaxb2-basics</artifactId>
            <version>0.12.0</version>
          </plugin>
        </plugins>
      </configuration>
    </plugin>

this is the catalog file:

  • xml version:

      <?xml version="1.0"?>
      <!DOCTYPE catalog
        PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
      <catalog
        xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"
        prefer="public">
        <rewriteSystem
          systemIdStartString="http://my.url/commonDefinitions"
          rewritePrefix="maven:my.package:common-xml-definitions:jar::!/xsd" />
      </catalog>
    
  • plain text version:

    REWRITE_SYSTEM "http://my.url/commonDefinitions" "maven:my.package:common-xml-definitions:jar::!/xsd"
    

The beginning ot the tagret XSD is:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:codef="http://my.url/commonDefinitions" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
  jxb:version="1.0" elementFormDefault="qualified">
  <xs:import namespace="http://my.url/commonDefinitions"
    schemaLocation="commonDefinitions.xsd" />
 <!-- ... -->
</xs:schema>

the maven error message for the XML-Catalog with DOCTYPE is:

[ERROR] Failed to execute goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.14.0:generate (MyProject generate-sources) on project MyProject: Error parsing catalog [jar:file:/d:/maven-repository/my/package/common-xml-definitions/1.0.0/common-xml-definitions-1.0.0.jar!/catalog.xml].: Connection timed out: connect -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.14.0:generate (MyProject generate-sources) on project MyProject: Error parsing catalog [jar:file:/d:/maven-repository/my/package/common-xml-definitions/1.0.0/common-xml-definitions-1.0.0.jar!/catalog.xml].
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error parsing catalog [jar:file:/d:/maven-repository/my/package/common-xml-definitions/1.0.0/common-xml-definitions-1.0.0.jar!/catalog.xml].
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.parseResolvedCatalogURIs (RawXJC2Mojo.java:1205)
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.setupCatalogResolver (RawXJC2Mojo.java:876)
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute (RawXJC2Mojo.java:432)
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute (RawXJC2Mojo.java:320)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0 (Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect (DualStackPlainSocketImpl.java:79)
    at java.net.AbstractPlainSocketImpl.doConnect (AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress (AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect (AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect (PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect (SocksSocketImpl.java:392)
    at java.net.Socket.connect (Socket.java:589)
    at java.net.Socket.connect (Socket.java:538)
    at sun.net.NetworkClient.doConnect (NetworkClient.java:180)
    at sun.net.www.http.HttpClient.openServer (HttpClient.java:463)
    at sun.net.www.http.HttpClient.openServer (HttpClient.java:558)

error message with plain text catalog ort XML without DOCTYPE:

[INFO] Parsing input schema(s)...
[DEBUG] Resolving publicId [http://my.url/commonDefinitions], systemId [commonDefinitions.xsd].
resolveSystem(commonDefinitions.xsd)
resolvePublic(http://my.url/commonDefinitions,commonDefinitions.xsd)
[DEBUG] Parent resolver has resolved publicId [http://my.url/commonDefinitions], systemId [commonDefinitions.xsd] to [null].
[DEBUG] SystemId [commonDefinitions.xsd] is not a Maven dependency resource URI. Returning parent resolver result [null].
[WARNING] Error while parsing schema(s).Location [ file:/D:/data/scm-workspace/MyProject/src/main/xsd/parad.xsd{6,46}].
org.xml.sax.SAXParseException: schema_reference.4: Schemadokument 'commonDefinitions.xsd' konnte nicht gelesen werden, da 1) das Dokument nicht gefunden werden konnte; 2) das Dokument nicht gelesen werden konnte; 3) das Root-Element des Dokuments nicht <xsd:schema> ist.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException (ErrorHandlerWrapper.java:203)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.warning (ErrorHandlerWrapper.java:99)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError (XMLErrorReporter.java:392)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr (XSDHandler.java:4154)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaWarning (XSDHandler.java:4149)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument1 (XSDHandler.java:2491)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument (XSDHandler.java:2193)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.resolveSchema (XSDHandler.java:2084)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.constructTrees (XSDHandler.java:1014)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema (XSDHandler.java:625)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema (XMLSchemaLoader.java:610)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar (XMLSchemaLoader.java:569)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar (XMLSchemaLoader.java:535)
    at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema (XMLSchemaFactory.java:254)
    at com.sun.tools.xjc.reader.xmlschema.parser.SchemaConstraintChecker.check (SchemaConstraintChecker.java:111)
    at com.sun.tools.xjc.ModelLoader.loadXMLSchema (ModelLoader.java:342)
    at com.sun.tools.xjc.ModelLoader.load (ModelLoader.java:162)
    at com.sun.tools.xjc.ModelLoader.load (ModelLoader.java:117)
    at org.jvnet.mjiip.v_2_3.XJC23Mojo.loadModel (XJC23Mojo.java:50)
    at org.jvnet.mjiip.v_2_3.XJC23Mojo.doExecute (XJC23Mojo.java:40)
    at org.jvnet.mjiip.v_2_3.XJC23Mojo.doExecute (XJC23Mojo.java:28)
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute (RawXJC2Mojo.java:478)
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute (RawXJC2Mojo.java:320)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: java.io.FileNotFoundException: D:\data\scm-workspace\MyProject\src\main\xsd\commonDefinitions.xsd (Das System kann die angegebene Datei nicht finden)
    at java.io.FileInputStream.open0 (Native Method)
    at java.io.FileInputStream.open (FileInputStream.java:195)
    at java.io.FileInputStream.<init> (FileInputStream.java:138)
    at java.io.FileInputStream.<init> (FileInputStream.java:93)
    at sun.net.www.protocol.file.FileURLConnection.connect (FileURLConnection.java:90)
1
Could you please post mvn -X log?lexicore
I can't immediately spot any problem in your pom.xml. Please send me a pull request with a test project somewhere under https://github.com/highsource/maven-jaxb2-plugin-support. I'll take a look.lexicore
@lexicore "Could you please post mvn -X log?" I already mosted the relevant lines from this log. there is nothing related to the plugin before this.Timothy Truckle

1 Answers

2
votes

sometimes reading carefully solves problems...

https://github.com/highsource/maven-jaxb2-plugin/wiki/Using-Catalogs:

Due to the bug in the XJC this only works if schemaLocation is not specified. So, unfortunately the following combination does not work at the moment.

PUBLIC "http://www.w3.org/1999/xlink" "w3c/1999/xlink.xsd"
<import namespace="http://www.w3.org/1999/xlink" schemaLocation="http://www.w3.org/1999/xlink.xsd" />

Removing the schemaLocation attribute from the import solved the problem.