Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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()) 
    System.out.println(fileNames);

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/.

share|improve this question
1  
This question isn't really gamedev related. It would be better suited for stackoverflow –  bummzack May 1 '13 at 20:58
    
But im using Slick2d, the particle class is from slick2d example page slick2d.org/wiki/index.php/Configurable_emitters_code_example –  Matthew May 1 '13 at 21:25
add comment

closed as off topic by bummzack, Nate, Anko, msell, Josh Petrie May 2 '13 at 15:21

Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

up vote 4 down vote accepted

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).

share|improve this answer
    
how do i get absolute data path from code, i want to load evreything from project room /res –  Matthew May 1 '13 at 20:53
    
@Matthew read the API documentation for the Java File class. –  jwenting May 2 '13 at 6:01
    
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 –  Matthew May 2 '13 at 10:16
    
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. –  Cristina May 2 '13 at 10:19
    
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 –  Matthew May 2 '13 at 10:33
show 5 more comments
 path="/res/particles/file.xml";
 emitter = ParticleIO.loadEmitter(path);

This fixed the problem thanks to Cristina

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.