jaid
Senior Newbie 
|
 |
«
Posted
2011-11-29 13:06:50 » |
|
Hey, I got a problem with runnable jars that I export with Eclipse. VM Call: java -Djava.library.path=D:\Users\Dario\Desktop\native\windows -jar gametest.jar Console log:  Exception points to: 1 2 3 4 5 6 7 8 9 10 11 12
| public static void main(String[] args) { try { AppGameContainer app = new AppGameContainer(new Game()); app.setIcon("i/default.png"); app.setDisplayMode(1024, 768, false); app.setTargetFrameRate(30); app.setMouseGrabbed(true); app.start(); } catch (SlickException e) { e.printStackTrace(); } } |
Everything is working fine in Eclipse. Any suggestions? =)
|
|
|
|
princec
|
 |
«
Reply #1 - Posted
2011-11-29 13:30:14 » |
|
That's not where the exception points to. Cas 
|
|
|
|
jaid
Senior Newbie 
|
 |
«
Reply #2 - Posted
2011-11-29 13:45:56 » |
|
Ah, thanks, the actual trigger is Game.java:47. 1 2 3 4 5 6 7
| try { for (String n : new File(ClassLoader.getSystemResource("i").toURI()).list()) i.put(n.substring(0, n.indexOf('.')), new Image("i/" + n)); i.put("clickable1", i.get("clickable0").getFlippedCopy(true, false)); } catch (URISyntaxException e) { e.printStackTrace(); } |
I'm still looking for help with bypass that exception.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
princec
|
 |
«
Reply #3 - Posted
2011-11-29 14:05:34 » |
|
How about you print out what those URIs look like after you've done all that monkeying with them? I have a feeling it will be quite obvious once you see them. Cas 
|
|
|
|
jaid
Senior Newbie 
|
 |
«
Reply #4 - Posted
2011-11-29 14:14:23 » |
|
Debug code: 1 2 3 4 5
| try { System.err.println(ClassLoader.getSystemResource("i").toURI().toString()); } catch (URISyntaxException e1) { e1.printStackTrace(); } |
Result in Eclipse: file:/D:/Users/Dario/Desktop/space/Devrays/bin/iResult as runnable jar: jar:file:/D:/Users/Dario/Desktop/gametest.jar!/i
|
|
|
|
nsigma
|
 |
«
Reply #5 - Posted
2011-11-29 15:33:56 » |
|
You can't create a File from a jar: URI. Check the JavaDoc for File - the URI must have a scheme equal to file (ie. begin file:) Quick Googling found this http://stackoverflow.com/questions/1429172/list-files-inside-a-jar-file - might be useful. Or just have a plain text file in the JAR with a list of all your images and parse that. Depends on where you're running - the above requires a security permission. Best wishes, Neil
|
Praxis LIVE - hybrid visual IDE for (live) creative coding
|
|
|
jaid
Senior Newbie 
|
 |
«
Reply #6 - Posted
2011-11-29 16:20:24 » |
|
Jar entry listing works in theory, but this would mean that I can't execute my projects through Eclipse anymore. Is there no way for both Eclipse debugging and exportet .jars? =/
|
|
|
|
sproingie
|
 |
«
Reply #7 - Posted
2011-11-29 17:44:56 » |
|
Use the index file that nsigma mentioned, and open all your resources with getResourceAsStream(). Resource location problems pretty much melt away when you do that.
|
|
|
|
jaid
Senior Newbie 
|
 |
«
Reply #8 - Posted
2011-11-29 19:45:27 » |
|
I prefer to not create a txt with an image index. This does not seem to be very productive and slows down the developement. I finally created a data initialization that automatically checks if it is a jar or not during the runtime and chooses the correct way to load files, works perfect for me: 1 2 3 4 5 6 7 8
| try { if (Game.class.getResource("/" + Game.class.getName().replace('.', '/') + ".class").toString().startsWith("file")) loadFiles(); else loadResources(); } catch (Exception e) { e.printStackTrace(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| static void loadFiles() {
try { for (String n : new File(ClassLoader.getSystemResource("i").toURI()).list()) i.put(n.substring(0, n.indexOf('.')), new Image("i/" + n)); } catch (URISyntaxException | SlickException e) { e.printStackTrace(); }
try { for (String n : new File(ClassLoader.getSystemResource("f").toURI()).list()) { if (n.endsWith("t")) { n = n.substring(0, n.indexOf('.')); f.put(n, new AngelCodeFont("f/" + n + ".fnt", "f/" + n + ".png")); } } } catch (URISyntaxException | SlickException e) { e.printStackTrace(); }
} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| static void loadResources() { try { Enumeration<JarEntry> en = new JarFile("gametest.jar").entries(); while (en.hasMoreElements()) { JarEntry n = (JarEntry) en.nextElement(); String name = n.getName(); if (name.startsWith("i") && name.indexOf('.') > -1) i.put(name.substring(2, name.indexOf('.')), new Image(name)); if (name.endsWith("fnt")) f.put(name.substring(2, name.indexOf('.')), new AngelCodeFont(name, name.substring(0, name.indexOf('.')) + ".png")); } } catch (IOException | SlickException e) { e.printStackTrace(); } } |
|
|
|
|
ra4king
|
 |
«
Reply #9 - Posted
2011-11-29 23:02:03 » |
|
"jar:" is not a recognized URI prefix, meaning you can not be able to create a File object of anything inside a zipped file (jar). You can however use the ZipInputStream class and its related classes to read file entries inside a zipped file 
|
|
|
|
Games published by our own members! Check 'em out!
|
|
nsigma
|
 |
«
Reply #10 - Posted
2011-11-29 23:28:37 » |
|
"jar:" is not a recognized URI prefix, meaning you can not be able to create a File object of anything inside a zipped file (jar). You can however use the ZipInputStream class and its related classes to read file entries inside a zipped file  JarFile et al extends ZipFile et al! btw, I mentioned File doesn't support the jar scheme already. 
|
Praxis LIVE - hybrid visual IDE for (live) creative coding
|
|
|
ra4king
|
 |
«
Reply #11 - Posted
2011-11-30 04:21:27 » |
|
Well excuuuuuse me 
|
|
|
|
|