title: My jar file won't load images
body: <p>I am currently writing a program that I need to send to a friend as a jar. The program has images that need to be loaded for the program to work properly and I want it all to be contained in the one jar. Currently it doesn't work from the executable jar or when I run it through command line. It works in netbeans however.</p>
  
  <p>Here's the code I'm using:</p>
  
  <p>To load the image I'm using:</p>
  
  <pre><code>protected ImageIcon createImageIcon(String path, String description)
  {
   java.net.URL imgURL = getClass().getClassLoader().getResource(path);
   if (imgURL != null)
   {
       return new ImageIcon(Toolkit.getDefaultToolkit()
                    .getImage(imgURL),description);
   }
   else
   {
       System.err.println("Couldn't find file: " + path);
       return null;
   }
  }
  </code></pre>
  
  <p>for the URL I've also tried just</p>
  
  <pre><code> getClass().getResource(path)
  </code></pre>
  
  <p>The line where the image is supposed to be created is:</p>
  
  <pre><code>this.img =createImageIcon(File.separator+"."+File.separator
             +"resources"+File.separator+"tiles"+File.separator+"tile.png","tile");
  </code></pre>
  
  <p>My jar file is setup with the folder containing the class files and the resource folder both on the top level of it.</p>
  
  <p>I have searched around for ways to resolve this, but I cannot find anything that works.</p>
  
  <p>Thanks. </p>