title: In java, how do you retrieve images from a jar file?
body: <p>I've been having problems exporting my java project to a jar (from Eclipse). There is a file that I've included in the jar named <code>images</code>. It contains all of the image files used by my project. The problem is, my references to those images only work when the project <em>isn't</em> in jar form. I can't figure out why and I'm wondering if I need to change the wording of the image references. This is what I'm doing to reference images:</p>
  
  <pre><code>    URL treeURL = null;
      Image tree = null;
      File pathToTheTree = new File("images/tree.png");
      try {
          treeURL = pathToTheTree.toURL();
      } catch (MalformedURLException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
      }
      try {
          tree = ImageIO.read(treeURL);
      } catch(IOException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>Most likely it is a simple problem, as I'm a beginner at coding. What do I need to change to make these references work when it's all in a jar?</p>