I found this suggestion on a Stack Exchange site to print out what the current directory is:

File file = new File(".");
for(String fileNames : file.list()) 

Basically, when I run a game in Eclipse, I get this:

Enter image description here

But when I compile the game and run it, it prints out this (it prints out the stuff that is in the same directory as the JAR file is). Images, and sound are working fine. It's just the XML file that is causing this.

Enter image description here

How do I make Java read XML files from res folder like it does for images and sound in Eclipse?

My particular code that loads the XML is at http://pastebin.com/59Nt7Dtd.

Slick2D documentation is at http://www.slick2d.org/javadoc/.


2 Answers 2


The reason why it works in Eclipse is because you are in the project root when you do this:

particleImage = new Image("res/particles/particle.png", false);

For consistency, put your XML file there as well or if you don't want to run it from Eclipse, but from a JAR, integrate an absolute data path in your code (do not hardcode it in your source files).

  • \$\begingroup\$ how do i get absolute data path from code, i want to load evreything from project room /res \$\endgroup\$
    – Matthew
    May 1, 2013 at 20:53
  • \$\begingroup\$ @Matthew read the API documentation for the Java File class. \$\endgroup\$
    – jwenting
    May 2, 2013 at 6:01
  • \$\begingroup\$ Ok so i made it absolute path but now this happends : shrani.si/f/2H/13W/131vAM3/error3.png , so my question is shouldnt the absolute path have filename inluded, the name of the file was 5.jar but it was not shown in the absolute path \$\endgroup\$
    – Matthew
    May 2, 2013 at 10:16
  • \$\begingroup\$ The absolute path is composed out of: DirPath + RelativePath + Filename. If you are trying to get the jar, your dirPath should be something like C:\Project\Particles and your relativePath \res (\bin) and the filaname a.xml (b.jar). Hope this clarifies it a bit. \$\endgroup\$
    – Cristina
    May 2, 2013 at 10:19
  • \$\begingroup\$ Shouldnt the path be something like this for this case D:\PathToJar\game.jar\res\particles\particleXmlFile.xml , because the particlexml file is inside the game.jar \$\endgroup\$
    – Matthew
    May 2, 2013 at 10:33
 emitter = ParticleIO.loadEmitter(path);

This fixed the problem thanks to Cristina


Not the answer you're looking for? Browse other questions tagged .