Question: We are programming a game, which shall be startable from a .jar file. First we created a Project in IntelliJ and loaded the Images from a ZIP with the following code:

```
ZipFile zf = null;
try {
    zf = new ZipFile(zipPath);
    Image Image = ImageIO.read(zf.getInputStream(zf.getEntry("Block/Air.png")));
} catch (IOException ignored) {}

```

Now the attempt without the ZIP (just from the .jar) is:

```
Image image=ImageIO.read(getClass().getResourceAsStream(path+ "Block/Air.png"));

```

It doesn't load any texture. Do you have a better way to do this in combination?

Edit:Seems not to be the Problem.

Answer: 
The Class.getResource and Class.getResourceAsStream methods take a URL (not a file path!) which is *relative to the root of each classpath entry.* For classpath entries which are .jar files, this means the path of a file packaged within the respective .jar file.

If your entire program is in one .jar file, the classpath consists of just one item: that .jar file. Therefore, there is only one classpath root, and the String you pass to getResourceAsStream is the URL of an entry within your .jar file. Do not include the path to the .jar file in that String.

If you are not sure what you should pass, examine your .jar file's contents. Every IDE (that I know of) provides a way to do this. You can also use any unzip utility to examine a .jar file, since every .jar file is actually a .zip file. (If you only have Windows, with no zip tools installed, make a copy of the .jar file and change the copy's extension to ".zip", then open it.)

Inside the .jar file are, of course, zip entries. The full path of the entry you want to load (without the path to the .jar file) is what you must pass to getResourceAsStream. getResourceAsStream accepts a URL, and URLs always use forward slashes (`/`) on all platforms, so do not use any backslashes. Also, the first character of the String must be `/`.

It is actually possible to specify a shorter path, depending on how your images are packaged in the .jar, but that is a separate topic. See [the documentation](http://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getResourceAsStream-java.lang.String-) for full details.

Side note: Never, ever write an empty catch block. Ever. That caught exception is by far the easiest way for you or anyone else to know when and why your program is not working. At the very least, put `exc.printStackTrace();` in your catch block. More often, the correct course of action is to abort the program with something like `throw new RuntimeException(exc);`. After all, your program can't continue to function properly if it can't load that image, right?
Why do you need to store your images in a zip file? If you're doing it to reduce the file size, you gain absolutely nothing from zipping it first. JAR files are zipped files anyway (if you don't believe me, rename your .jar file to .zip, and try to open it). What you're basically doing is attempting to zip an already zipped file, which doesn't really do anything.

I would recommend you unzip your images and store them somewhere like < resources >/images

If you insist on leaving them zipped, you'll need to change it to something like this. Otherwise, it's looking for the zip file in the working directory (directory from which the jar was executed)

```
ZipFile zf = new ZipFile(getClass().getResourcesAsStream("path/to/zip"));

```

Disclaimer: I am not familiar with the ZipFile class, so I do not know if that constructor exists.