LWJGL
May 22, 2012, 04:53:00 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.8.3 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: Applet - get Files from jar  (Read 2990 times)
Dragbone
Newbie
*
Posts: 8


« on: February 02, 2010, 10:00:45 »

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
Logged
kappa
Administrator
Nerdus Imperius
*****
Posts: 961



« Reply #1 on: February 02, 2010, 11:28:27 »

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
Logged
Dragbone
Newbie
*
Posts: 8


« Reply #2 on: February 02, 2010, 11:59:10 »

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 ;-) )
Logged
kappa
Administrator
Nerdus Imperius
*****
Posts: 961



« Reply #3 on: February 02, 2010, 12:01:14 »

if you can upload a simple test case applet + source, could help point you in the right direction.
Logged
Dragbone
Newbie
*
Posts: 8


« Reply #4 on: February 02, 2010, 12:31:20 »

Applet:
http://dragoon.gamez-interactive.de/testProject/

And the two sourcefiles:
http://dragoon.gamez-interactive.de/testProject/game/App.java
(-> Line 123)
http://dragoon.gamez-interactive.de/testProject/game/Sprite.java

PS: Sorry, the code is a bit messy, refactoring is on the todo list ;-)
Logged
kappa
Administrator
Nerdus Imperius
*****
Posts: 961



« Reply #5 on: February 02, 2010, 12:38:57 »

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

you can't use FileInputStream to read files from a jar file.
Logged
kappa
Administrator
Nerdus Imperius
*****
Posts: 961



« Reply #6 on: February 02, 2010, 12:41:41 »

you must do something like

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

btw the import from ResourceLoader is

import org.newdawn.slick.util.ResourceLoader;
Logged
Dragbone
Newbie
*
Posts: 8


« Reply #7 on: February 02, 2010, 12:59:39 »

If i use
Code:
this.tex = TextureLoader.getTexture(getImageExtension(fileName),
ResourceLoader.getResource(fileName).openStream());
i get this AccessControlException:
Quote
Exception 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...
Logged
kappa
Administrator
Nerdus Imperius
*****
Posts: 961



« Reply #8 on: February 02, 2010, 13:05:14 »

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"
Logged
Dragbone
Newbie
*
Posts: 8


« Reply #9 on: February 02, 2010, 13:20:36 »

*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 Cheesy

another day wasted on something trivial^^
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!