title: Image not displaying in JAR file, but display on Eclipse run
body: <p>I see <a href="https://stackoverflow.com/questions/23482523/images-not-being-displayed-in-jar-file">other</a> StackOverflow <a href="https://stackoverflow.com/questions/21987967/java-swing-images-not-displaying-when-run-from-jar-file">users</a> have been having this error. However, when I try what the first person did (make it use <code>getClass().getClassLoader().getResource(myPath)</code>, which is URL), it doesn't work in the Eclipse IDE run nor in the JAR file. I can't make sense of one of the answers on <a href="https://stackoverflow.com/questions/5085156/images-are-not-displaying-in-jar-but-displaying-in-compiler">here</a>, but I do understand this one: </p>
  
  <blockquote>
    <p>The getImage call is looking in the file system working directory, not inside the Jar file. This is why the jar file loads the images successfully when they are placed in the same directory outside the jar file. If the images are bundled in the jar file, they are no longer file system files to be accessed, but rather Jar file resources. There is a different way to load these, but sorry, I don't know it off the top of my head</p>
  </blockquote>
  
  <p>Before this, I thought the image file (whose relative path is <code>/images/folder.jpg</code> wasn't being included in the JAR file. I extracted it and could not find the image.) In attempt to address that, I included <code>images</code> folder in build path (<code>Project &gt; Properties &gt; Java build path &gt; Source</code>). After doing so, I extract JAR file again, and notice the picture is there, but not in images folder.</p>
  
  <p>This is what I tried from the Java code side: </p>
  
  <pre><code>//this.selectDirector = new JButton(new ImageIcon(getClass().getClassLoader().getResource("images/folder.jpg")));
  this.selectDirectory = new JButton(new ImageIcon("images/folder.jpg"));
  </code></pre>
  
  <p>Is there answer to this (or way to do what the quote says should be done)?
  UPDATE: </p>
  
  <p>I moved <code>images</code> folder to inside <code>bin</code> folder, and removed it from the build path (so that only <code>src</code> folder was on the build path). For good measure, I also placed it in the <code>src</code> folder.  I updated my two lines of code to:</p>
  
  <pre><code>this.selectDirector = new JButton(new ImageIcon(getClass().getClassLoader().getResource("images/folder.jpg")));
  //this.selectDirectory = new JButton(new ImageIcon("src/images/folder.jpg"));
  </code></pre>
  
  <p>Now, it works from Eclipse, but still doesn't work from JAR file (it's throwing <code>NullPointerException</code>). </p>