title: How to load XMLCatalog from classpath resources (inside a jar), reliably?
body: <p>Below are some code fragments that indicate what I am trying at the moment, but its unreliable. Princiaply I think
  because you can only register a protocol handler once, and occasionally other libraries may be doing this first.</p>
  
  <pre><code>import org.apache.xerces.util.XMLCatalogResolver;
  
  
  
  public static synchronized XMLCatalogResolver getResolver() {
          String c[] = {"classpath:xml-catalog.xml"};
          if (cr==null) {
  
              log.debug("Registering new protcol handler for classpath");
              ConfigurableStreamHandlerFactory configurableStreamHandlerFactory = new ConfigurableStreamHandlerFactory("classpath", new org.fao.oek.protocols.classpath.Handler(XsdUtils.class.getClassLoader()));
              configurableStreamHandlerFactory.addHandler("http", new sun.net.www.protocol.http.Handler());
  
  
              URL.setURLStreamHandlerFactory(configurableStreamHandlerFactory);
  
              log.debug("Creating new catalog resolver");
  
          cr = new XMLCatalogResolver(c);
  
          }
          return cr;
      }
  </code></pre>
  
  <p>xml-catalog.xml contains:</p>
  
  <pre><code>&lt;catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"&gt;
  &lt;group  prefer="public"  xml:base="classpath:org/me/myapp/xsd/" &gt;  
    &lt;uri name="http://www.w3.org/XML/1998/namespace" uri="xml.xsd"/&gt;
    &lt;uri name="http://www.w3.org/1999/xlink" uri="xlink.xsd" /&gt;
    &lt;uri name="http://www.w3.org/2001/XMLSchema" uri="XMLSchema.xsd" /&gt;
    &lt;uri name="http://purl.org/dc/elements/1.1/" uri="dc.xsd" /&gt;
    &lt;uri name="http://www.loc.gov/mods/v3"  uri="mods-3.3.xsd" /&gt;
   &lt;/group&gt;
  &lt;/catalog&gt;
  </code></pre>
  
  <p>Obviously - the xsd files exist at the right place in the classpath.</p>