title: Why would ClassLoader.getResourceAsStream() return null?
body: <p>Having the following code broken deliberately to identify the source of a NullPointerException in something that should have been very simple but turns out to drive me nuts:</p>
  
  <pre><code>Properties properties = new Properties();
  Thread currentThread = Thread.currentThread();
  ClassLoader contextClassLoader = currentThread.getContextClassLoader();
  InputStream propertiesStream = contextClassLoader.getResourceAsStream("resource.properties");
  if (propertiesStream != null) {
    properties.load(propertiesStream);
    // TODO close the stream
  } else {
    // Properties file not found!
  }
  </code></pre>
  
  <p>I get the "Properties file not found!" error, i.e. contextClassLoader.getResourceAsStream("resource.properties"); <strong>returns null</strong>.</p>
  
  <p>This is a CXF-based client and I verified that the "resource.properties" file <strong><em>is</em></strong> in the current directory in which the client's jar resides (and runs).</p>
  
  <p>I also verified the absolute path by including the following diagnostic code:</p>
  
  <pre><code>            File file = new File("resource.properties");
              System.out.println(file.getAbsolutePath());
  </code></pre>
  
  <p>The absolute path points to where the client's jar is.</p>
  
  <p>I also tried finding out the context of the class loader, using:</p>
  
  <pre><code>  System.out.println(Thread.currentThread().getContextClassLoader());
  </code></pre>
  
  <p>but instead some directory structure <a href="https://stackoverflow.com/a/14052579">as demonstrated here</a>, all I get is:</p>
  
  <blockquote>
    <p>com.simontuffs.onejar.JarClassLoader@1decdec</p>
  </blockquote>
  
  <p>Why would ClassLoader.getResourceAsStream() return null?</p>
  
  <p>What am I missing?</p>