Hi !
Featured games (88)
games approved by the League of Dukes
Games in Showcase (681)
Games in Android Showcase (196)
games submitted by our members
Games in WIP (746)
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  
  Loading files after export  (Read 951 times)
0 Members and 1 Guest are viewing this topic.
Offline blaa_vogn

Junior Devvie

Projects: 2

« Posted 2013-02-27 17:58:45 »

Hi everybody

I am trying to make a game, and have run into a problem.

I have made a game, which consists of several levels.
Each level is saved as an xml-file, which is loaded and parsed.
loadLevel(new File("resources/levels/"+levelID));

Everything has been working until I tried to export the program, after exporting the program I can't find a way to load my level-files.
I have tried to place my files within the game-jar, and I have tried to place them at the same level as my jar-file, but I can't seem to reach them.

So what am I doing wrong?

Best wishes
Blaa Vogn
Offline sproingie

JGO Kernel

Medals: 202

« Reply #1 - Posted 2013-02-27 18:26:11 »

That's because you're using File, which doesn't work inside a jar.  You need to access it as a resource instead.

If you're using libGDX, use Gdx.files.internal instead.  Slick also has its own resource loader, though I'm not sure you're any better off using it.

Offline blaa_vogn

Junior Devvie

Projects: 2

« Reply #2 - Posted 2013-02-28 15:44:02 »

Thank you very much it is working, and I only need music for my game to be complete Cheesy.

My only problem is now, that when I try to compile and run the program with Eclipse, I can't find the files.

I guess my project has the wrong configuration, I have tried to include the resource folder to the "Java build path", but that doesn't help. Any ideas?

I could just either export the game each time I want to try it, or run with two different version, but it seems rather frustrating.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jonjava
« Reply #3 - Posted 2013-02-28 15:50:09 »


Include "res" into java build path and use

URL url = this.getClass().getClassLoader().getResource( "myres_name_blabla.txt" );

Offline blaa_vogn

Junior Devvie

Projects: 2

« Reply #4 - Posted 2013-02-28 19:32:01 »

Okay, it is working.

I don't quite understand why "myres_name_blabla.txt", is correct and "res/myres_name_blabla.txt" isn't, but it is working!
Offline cylab

JGO Wizard

Medals: 135

« Reply #5 - Posted 2013-02-28 19:40:23 »

because if you add res to your build path, it takes the contents of res and puts them in the jar...

Mathias - I Know What [you] Did Last Summer!
Offline jonjava
« Reply #6 - Posted 2013-03-01 00:41:54 »

Indeed, since both src (by default) and now res are in the build path, their CONTENTS will be put into the jar.

If you would have created a folder under "src" (src/res/my_res.txt, for example) then "res/my_res.txt" would work because res is now part of src's CONTENTS (and res would no longer be in the build path directly).

Offline Icecore
« Reply #7 - Posted 2013-03-01 01:25:38 »

../bin/res/myres_IN.txt // auto moved here from /src/ when run application (Eclipse)

i use this =)
for in jar - wher: path = res/myres_IN.txt (../src/res/myres_IN.txt)
      ClassLoader c = ClassLoader.getSystemClassLoader();
      InputStream is = c.getSystemResourceAsStream(path);
      if(is == null){throw new FileNotFoundException(path);}

and for out - wher: path = res/myres_Out.txt (../res/myres_Out.txt)
// need move res folder near jar when export it
out have bug - need run like "java -jar blabla.jar"
if you run from out folder like "java -jar folder_A/blabla.jar" (C:/folder_0/folder_A/blabla.jar)
java search "res" in "folder_0" not wher jar itself  (not in "folder_A")^^
      File file = (new File(path));   
      if(!file.exists()){throw new FileNotFoundException(path);}
      InputStream is = new FileInputStream(file);

i prefer out.

Happy – happy day to you ^^
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

GrandCastle (28 views)
2016-07-01 09:13:47

GrandCastle (30 views)
2016-07-01 09:09:45

CopyableCougar4 (84 views)
2016-06-25 16:56:52

Hydroque (117 views)
2016-06-22 02:17:53

SwampChicken (119 views)
2016-06-20 13:22:57

SwampChicken (120 views)
2016-06-20 13:22:49

SwampChicken (112 views)
2016-06-20 13:22:26

Hydroque (157 views)
2016-06-15 08:22:50

Hydroque (152 views)
2016-06-13 06:40:55

DarkCart (255 views)
2016-05-29 02:30:33
Making a Dynamic Plugin System
by Hydroque
2016-06-25 00:13:25

Java Data structures
by BinaryMonkL
2016-06-13 21:22:09

Java Data structures
by BinaryMonkL
2016-06-13 21:20:42

FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17 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‑
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!