Applet - get Files from jar

Started by Dragbone, February 02, 2010, 18:00:45

Previous topic - Next topic



I'm running my game as an applet but i'm stuck at loading the textures.
I'd like to have the image files in another jar (res.jar) file which is in the classpath.
Quote<param name="al_jars" value="res.jar, slick.jar, App.jar, lwjgl.jar.pack.lzma, jinput.jar.pack.lzma, lwjgl_util.jar.pack.lzma">

Now i wanted to load those textures but i can't find the right way to access them, everything i tried resulted in an FileNotFoundException.
The content of res.jar looks something like this:
  L graphics
      L ship.png
      L enemy.png
      L bullet.png

I'm using slick's TextureLoader so i need a string pointing to the files (if it's even possible).



it does work (with slick) as i've done used it many times.

you sure res.jar contains the files? (have you manually opened the jar with a zip viewer program?)

you should also consider using slicks ResourceLocator with the TextureLoader


Yup, all the files are where they should be, but i don't know how i have to adress them.
Do you have any working example or can you give me some pointers on how to do it? (Java is new to me but i'm eager to learn ;-) )


if you can upload a simple test case applet + source, could help point you in the right direction.


ahh, can't believe I didn't spot this earlier.

you can't use FileInputStream to read files from a jar file.


you must do something like

texture = TextureLoader.getTexture("PNG", ResourceLoader.getResource("data/wall.png"));

btw the import from ResourceLoader is

import org.newdawn.slick.util.ResourceLoader;


If i use
this.tex = TextureLoader.getTexture(getImageExtension(fileName),

i get this AccessControlException:
QuoteException in thread "Thread-19" access denied ( .\data\graphics\tr.png read)
   at Source)
   at Source)
   at java.lang.SecurityManager.checkPermission(Unknown Source)
   at java.lang.SecurityManager.checkRead(Unknown Source)
   at Source)
   at org.newdawn.slick.util.FileSystemLocation.getResource(
   at org.newdawn.slick.util.ResourceLoader.getResource(
   at game.Sprite.<init>(Unknown Source)
   at game.App.gameLoop(Unknown Source)
   at game.App$ Source)
The jar is signed, so that shouldn't be the problem...


also don't use backslash as that is windows only, always use forward slash as that will work everywhere, and remove the initial slash, you shouldn't need it, so it should read as



it was the initial slash (it was a slash, java seems to translate them into backslashes when run on windows)

it's working now, thanks a lot :D

another day wasted on something trivial^^