Applet - get Files from jar

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

Previous topic - Next topic

Dragbone

Heyho,

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:
Quote
data
  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).

Regards
Dragbone

kappa

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

Dragbone

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 ;-) )

kappa

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


kappa

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

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

kappa

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;

Dragbone

If i use
this.tex = TextureLoader.getTexture(getImageExtension(fileName),
					ResourceLoader.getResource(fileName).openStream());

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

kappa

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

"data/graphics/tr.png"

Dragbone

*dang*
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^^