title: Java - Spring Ws - Loading Relative Includes in XSD files (Tomcat 8)
body: <p>I created a Spring web service which creates a dynamic WSDL from a collection of XSD files using the following code:</p>
  
  <pre><code>Resource[] schema = {
              new ClassPathResource(
                      "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/NE2008/coreschemas/NarrativeBlock.xsd"),
              new ClassPathResource(
                      "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/NE2008/coreschemas/datatypes-base.xsd"),
              new ClassPathResource(
                      "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/NE2008/coreschemas/infrastructureRoot.xsd"),
              new ClassPathResource(
                      "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/NE2008/multicacheschemas/PRPA_IN201305UV02.xsd"),
              new ClassPathResource(
                      "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/NE2008/multicacheschemas/PRPA_IN201306UV02.xsd"),
              new ClassPathResource(
                      "schema/service/XCPD.SupportMaterials.v9/schema/IHE/XCPD_PLQ.xsd"),
              new ClassPathResource(
                      "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/XCPD_PRPA.xsd") };
      CommonsXsdSchemaCollection collection = new CommonsXsdSchemaCollection(
              schema);
      collection.setInline(true);
      return collection;
  </code></pre>
  
  <p>The XSD files used to create the dynamic WSDL include other various schema files using include statements like the following:</p>
  
  <pre><code>&lt;xs:include schemaLocation="../coreschemas/voc.xsd"/&gt;
  &lt;xs:include schemaLocation="../coreschemas/datatypes.xsd"/&gt;
  </code></pre>
  
  <p>When I run the code in a Tomcat 8 container, I receive the following exception:</p>
  
  <pre><code>Caused by: java.lang.IllegalArgumentException: The resource path [/../coreschemas/infrastructureRoot.xsd] has been normalized to [null] which is not valid
  </code></pre>
  
  <p>Spring's URI resolver prepends the "/" in front of the path, even though this file being referenced is a relative path (not an absolute path) and fails when importing the schema.  </p>
  
  <p>It should be noted that this application ran fine on Tomcat 7.  When trying to migrate it to Tomcat 8, the issues are arising.  </p>
  
  <p>Tomcat 8 did change the way how web resources are now being loaded.  <a href="http://www.coderanch.com/t/644145/Tomcat/Tomcat-Resource-loading" rel="noreferrer">More Information from Java CodeRanch</a>...  </p>
  
  <p>Any ways long story short, is there a way to force Spring that the URI resolver should treat relative files correctly?  If I look at the "collectionBaseURI" property on the resolver Spring uses (ClasspathUriResolver), this value is null.  Is there a way to set this base URI as well?</p>
  
  <p><strong>EDIT</strong> I can fix this issue by converting all relative paths to absolute paths to schemas...  however I don't want to apply this fix across hundreds of files.</p>