title: getResource() can't load content in a jar
body: <p>I can successfully load resources that stand in some package of my src/ dir in eclipse. Now, I export the jar (right click src, export, jar, and keep default settings) and can't have the resource loaded in another eclipse project.</p>
  
  <p>I build the path to the resource by indicating a class standing in the same package name:</p>
  
  <pre><code>URL out = getClass().getClassLoader().getResource(packageName(getClass())+"file.glsl");
  // out is null when loaded from a jar!!   
  
  protected static String packageName(Class&lt;?&gt; clazz){
      return packageName(clazz.getPackage());
  }
  protected static String packageName(Package p){
      return c + p.getName().replace('.', c) + c;
  }
  protected static char c = File.separatorChar;
  </code></pre>
  
  <p>Do you see any wrong way?
  I tried:</p>
  
  <ul>
  <li>getClass().getResource()</li>
  <li>getClass().getClassLoader().getResource()</li>
  <li>getClass().getClassLoader().getResourceAsStream()</li>
  <li>Thread.currentThread().getContextClassLoader().getResource()</li>
  <li>adding/removing the '/' char at the begining of the package name</li>
  <li>using either '/', '\', or File.separatorChar, and even '.', all failed.</li>
  </ul>
  
  <p>I verified that:</p>
  
  <ul>
  <li>jar contains the resource (expanding the jar content in eclipse project's "Referenced Libraries")</li>
  <li>packageName(getClass())+filename) returns a clean name: "\org\jzy3d\plot3d\rendering\ddp\algorithms\dual_peeling_init_vertex.glsl"</li>
  </ul>
  
  <p>I endlessly retrieve a null :/</p>
  
  <hr>
  
  <p>EDIT: screenshot and code to show that "that should work"</p>
  
  <p><img src="https://i.stack.imgur.com/AOJU6.png" alt="enter image description here"> </p>
  
  <p>You can retrieve this <a href="http://jzy3d.org/misc/jarresources/jarresources.zip" rel="noreferrer">a SSCCE zipped eclipse project here</a></p>
  
  <p>A user class</p>
  
  <pre><code>public class User {
      public static void main(String[] args) {
          Loader pair = new Loader(SomeClass.class, "shade_vertex.glsl");
          System.out.println("found:" + pair.getURL());
  
      }
  }
  </code></pre>
  
  <p>Providing class dynamically with new SomeClass().getClass() produce the same result.</p>
  
  <p>The loader</p>
  
  <pre><code>package com.pkg.loader;
  
  import java.io.File;
  import java.net.URL;
  
  public class Loader {
      public Loader(Class&lt;?&gt; c, String file) {
          this(packageName(c.getPackage()), file);
      }
  
      public Loader(Package p, String file) {
          this(packageName(p), file);
      }
  
      protected Loader(String pack, String file) {
          this.pack = pack;
          this.file = file;
      }
  
      public String getStringPath() {
          return pack+file;
      }
  
      public URL getURL() {
          URL out = Thread.currentThread().getContextClassLoader().getResource(getStringPath());
          if(out==null)
              throw new RuntimeException("unable to find shader URL for :'"+getStringPath()+"'");
          return out;
      }
  
      protected static String packageName(Class&lt;?&gt; clazz){
          return packageName(clazz.getPackage());
      }
  
      protected static String packageName(Package p){
          return c + p.getName().replace('.', c) + c;
      }
  
      protected static char c = File.separatorChar;
  
      protected String pack;
      protected String file;
  }
  </code></pre>
  
  <p>The marker class </p>
  
  <pre><code>public class SomeClass {}
  </code></pre>