title: URL to load resources from the classpath in Java
body: <p>In Java, you can load all kinds of resources using the same API but with different URL protocols:</p>
  
  <pre><code>file:///tmp.txt
  http://127.0.0.1:8080/a.properties
  jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class
  </code></pre>
  
  <p>This nicely decouples the actual loading of the resource from the application that needs the resource, and since a URL is just a String, resource loading is also very easily configurable.</p>
  
  <p>Is there a protocol to load resources using the current classloader?
  This is similar to the Jar protocol, except that I do not need to know which jar file or class folder the resource is coming from.</p>
  
  <p>I can do that using <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)" rel="noreferrer"><code>Class.getResourceAsStream("a.xml")</code></a>, of course, but that would require me to use a different API, and hence changes to existing code. I want to be able to use this in all places where I can specify a URL for the resource already, by just updating a property file.</p>