title: Cannot resolve the name 'X' to a(n) 'type definition' component
body: <p>There are many postings with the same title as this. I have looked at many of them, but their situations seem to be different from mine.</p>
  
  <p>I have a Java application that is configured at run-time by an XML file. There is a corresponding XML schema that defines the structure of the XML. The schema imports other schema to use type definitions they define. The application reads in the schema and configuration file and loads the XML as Java objects.</p>
  
  <p>The application is built using Apache Maven and the maven-jaxb2-plugin is used to translate the schema definitions into Java classes so the application can ingest the XML configuration information. Everything builds successfully and from what I can tell, the XJC generated classes are correct and in the correct locations.</p>
  
  <p>I'm running into a problem when I attempt execute the application, which first reads in the XML and load it as Java objects. An example exception follows.</p>
  
  <pre><code>[2018-08-09 10:31:05.056] ERROR: common.ConfigLoader:121 - Exception: 
  org.xml.sax.SAXParseException; lineNumber: 291; columnNumber: 80; src-resolve: Cannot resolve the name 'sc:ExpectedDataFormatEnum' to a(n) 'type definition' component.
      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
      at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(XSDHandler.java:4162)
      at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaError(XSDHandler.java:4145)
      at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getGlobalDecl(XSDHandler.java:1678)
      at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDElementTraverser.traverseNamedElement(XSDElementTraverser.java:405)
      at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDElementTraverser.traverseLocal(XSDElementTraverser.java:194)
      at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.traverseLocalElements(XSDHandler.java:3618)
      at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:633)
      at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:617)
      at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:575)
      at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:541)
      at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema(XMLSchemaFactory.java:252)
      at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:627)
      at {removed}.ConfigLoader.load(ConfigLoader.java:91)
      at {removed}.Launcher.main(Launcher.java:121)
  [2018-08-09 10:31:05.058] ERROR: wf.Launcher:122 - Unable to load configuration file
  </code></pre>
  
  <p>I suspect the problem is related to how the imported schemae are being referenced/resolved at run-time. I use an XML catalog (a new concept for me) to resolve schema locations during the build. Do I need something similar to resolve the location at run time?</p>
  
  <p>For context, here are snippets of relevant files.</p>
  
  <p>Schema that is imported by the application schema (security-common.xsd):</p>
  
  <pre><code>&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="security_common"
    xmlns:sc="security_common" elementFormDefault="qualified" attributeFormDefault="unqualified"&gt;
  
    &lt;xs:simpleType name="TypeList"&gt;
      &lt;xs:list itemType="xs:string" /&gt;
    &lt;/xs:simpleType&gt;
  
    &lt;xs:simpleType name="ExpectedDataFormatEnum"&gt;
      &lt;xs:restriction base="xs:string"&gt;
        &lt;xs:enumeration value="STRING" /&gt;
        &lt;xs:enumeration value="BYTE_ARRAY" /&gt;
      &lt;/xs:restriction&gt;
    &lt;/xs:simpleType&gt;
  
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>Application schema that uses the schema above (config-schema.xsd):</p>
  
  <pre><code>&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="injector"
    xmlns:inj="injector" xmlns:sc="security_common" xmlns:camel="camel_config"
    elementFormDefault="qualified" attributeFormDefault="unqualified"&gt;
  
    &lt;xs:import namespace="security_common" /&gt;
    &lt;xs:import namespace="camel_config" /&gt;
  
    ...
    &lt;xs:complexType name="WireCaptureConfig"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element name="expected-data-format" type="sc:ExpectedDataFormatEnum" /&gt;
        ...
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
    ...
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>The XML catalog file:</p>
  
  <pre><code>PUBLIC "security_common" "maven:{removed}:security-common:jar::!/config/security-common.xsd"
  PUBLIC "camel_config" "maven:{removed}:security-common:jar::!/config/camel-config.xsd"
  </code></pre>
  
  <p>My understanding is that the catalog file maps the schema namespaces to maven artifacts, which represent the schemae to be imported/referenced. It seems like a little black magic, but it does work.</p>
  
  <p>The exception thrown would seem to indicate that the application cannot "see" the imported schema definitions. Based upon what has been described, is there a solution to this problem? If other information needs to be provided, please let me know and I'll see what I can do.</p>