Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  URI is not hierarchical  (Read 4921 times)
0 Members and 1 Guest are viewing this topic.
Offline jaid

Senior Newbie





« Posted 2011-11-29 14:06:50 »

Hey,
I got a problem with runnable jars that I export with Eclipse.

VM Call:
Quote
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(); // LINE 31
     } catch (SlickException e) {
         e.printStackTrace();
      }
   }


Everything is working fine in Eclipse. Any suggestions? =)
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2011-11-29 14:30:14 »

That's not where the exception points to.

Cas Smiley

Offline jaid

Senior Newbie





« Reply #2 - Posted 2011-11-29 14: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()) // LINE 47 // For every image file in src\i
           i.put(n.substring(0, n.indexOf('.')), new Image("i/" + n)); // load and put to ArrayList<Image> i
        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!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2011-11-29 15: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 Smiley

Offline jaid

Senior Newbie





« Reply #4 - Posted 2011-11-29 15: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/i

Result as runnable jar:
jar:file:/D:/Users/Dario/Desktop/gametest.jar!/i
Offline nsigma
« Reply #5 - Posted 2011-11-29 16: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 - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline jaid

Senior Newbie





« Reply #6 - Posted 2011-11-29 17: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? =/
Offline sproingie

JGO Kernel


Medals: 202



« Reply #7 - Posted 2011-11-29 18: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.
Offline jaid

Senior Newbie





« Reply #8 - Posted 2011-11-29 20: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();
      }
   }
Offline ra4king

JGO Kernel


Medals: 341
Projects: 2
Exp: 5 years


I'm the King!


« Reply #9 - Posted 2011-11-30 00: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 Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nsigma
« Reply #10 - Posted 2011-11-30 00: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 Smiley

JarFile et al extends ZipFile et al!

btw, I mentioned File doesn't support the jar scheme already.  Wink

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline ra4king

JGO Kernel


Medals: 341
Projects: 2
Exp: 5 years


I'm the King!


« Reply #11 - Posted 2011-11-30 05:21:27 »

Well excuuuuuse me Smiley

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (16 views)
2014-07-30 21:08:39

Riven (22 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!