2
private ConfigurableEmitter emitter;

File xmlFile = new File("ressources/emitter.xml");
emitter = ParticleIO.loadEmitter(xmlFile);

If I launch the project in eclipse, everything will works fine, but after I export my project and use JarSplice to create a .jar file, when I launch the jar file using the command prompt, the program will crash launching a FileNotFoundException, saying it cannot find the path specified.

java.io.FileNotFoundException: ressources\emitter.xml (The system cannot find the
path specified)

The surprising thing is that just before opening the xml file, I open a .png file located at the same place as the xml file, and this without any problem. In addition, when I open the .jar file I exported using winrar, I can find my xml file under the ressources folder. What can be the problem here?

Thank you!

EDIT :

Code with solution:

InputStream i=this.getClass().getClassLoader().
    getResourceAsStream("ressources/test.xml");
emitter = ParticleIO.loadEmitter(i);
Theriotgames Riot
  • 333
  • 3
  • 6
  • 14

1 Answers1

2

When you pack your project to JAR your resource don't live on disk, but are compressed into the JAR itself and you have to load as resource.
There are a lot of guide on SO on how to load resource from JAR using ClassLoader.getResourceAsStrem() (follow this link)

Community
  • 1
  • 1
Luca Basso Ricci
  • 17,829
  • 2
  • 47
  • 69
  • I'm sorry to ask this much, but can you please tell me how to use your solution in my code? I really can't manage to get it to work :(. And also, how come manage to laod the .png file, but not the .xml file, when they're both located in the same folder? Thank you really much – Theriotgames Riot Aug 07 '13 at 02:07