title: How to bundle images within a .jar file?
body: <p>Ok i'm having some problems with distributing my .jar file. When i just run the program from NetBeans it works, but if i try to run it from the dist folder it doesn't work (none of the images get loaded).</p>
  
  <p>Here is the hierarchy of my program:</p>
  
  <ul>
  <li>src/img/<em>random images</em></li>
  <li>src/myapp/<em>source files</em></li>
  </ul>
  
  <p>I load images with this function:</p>
  
  <pre><code>public BufferedImage getImg(String path) throws IOException {
      if (this.getClass().getResource(path) != null) {
          return ImageIO.read(this.getClass().getResource(path));
      } else {
          return null;
      }
  }
  </code></pre>
  
  <p>And after that:</p>
  
  <pre><code>BufferedImage image = getImg("../img/static_bg.png");
  if (image != null) {
      g.drawImage(image, 309, 884, this);
  }
  </code></pre>
  
  <p>After i build my project the images are in the jar file, but they aren't getting loaded. Any ideas why?</p>