title: Why is ClassLoader created from specific class when holds global information?
body: <p>I just came to realise that this will sometimes return <code>null</code> (print null in console):</p>
  
  <pre><code>package myproject;
  public class A {
     public static void main(String[] args) throws Exception
     {
       System.out.println(A.class.getClassLoader().getResource("A.class"));
     }
  }
  </code></pre>
  
  <p>Even though the ClassLoader is created from <code>A.class</code> it has nothing to do with it. It will load resources from the currently running classpath.</p>
  
  <p>I realised this when I was running Maven test classes which run, by default, in <code>project/target/test-classes</code> while the normal classes, like <code>A</code> above, are in <code>project/target/classes/</code>.</p>
  
  <p>I think this is very confusing. Why don't we get something like <code>Class.getClassLoader</code> to make it obvious that this is a global thing? Also, since ClassLoader is useless, what do developers use to load resources relative to their projects? If you include <code>.jar</code> dependency it works, resources included.</p>