Java - Registering custom URL protocol handlers
<p>I tried to register a custom URL handler for a classpath protocol, as described in <a href="http://stackoverflow.com/questions/861500/url-to-load-resources-from-the-classpath-in-java">another thread</a>. Here is the code:</p>

<pre><code>package com.mycompany;

import org.junit.Test;
import java.net.MalformedURLException;
import java.net.URL;
import com.mycompany.protocol.classpath.Handler;

public class ParserTest {
    @Test
    public void testParsing() throws MalformedURLException {      
        System.out.println(System.getProperty("java.protocol.handler.pkgs"));

        //URL url = new URL(null, "classpath://com.mycompany/hello-world.xml", new Handler(ClassLoader.getSystemClassLoader()));
        URL url = new URL("classpath://com.mycompany/hello-world.xml");
    }
}
</code></pre>

<p>The test case has the following JVM arguments:</p>

<pre><code>-Djava.protocol.handler.pkgs=com.mycompany.protocol
</code></pre>

<p>The <code>System.out.println</code> line properly outputs <code>com.mycompany.protocol</code>, so the property is being set. However, it looks like it's not being taken into effect, because the above call will throw a <code>java.net.MalformedURLException: unknown protocol: classpath</code> exception.</p>

<p>If I provide the handler explicitly as in the commented line, everything is fine. However, I would rather not provide it explicitly - it should be done automatically.</p>

<p>What am I doing wrong?</p>
