read/parse a text file inside the Jar file? Or use webstart to specify the file?

Hi
I am making a game and today i started to make a jar file and a jnlp for webstart.

The problem is that the game has to read and parse the file xmltest.xml,this works when I run it from Eclipse or start the Jar file manually when the file is outside the jar. When I move the jar to a standalone directory so that “xmltest.xml” is inside the jar root the file cant be found.

How can I do this? Do i have to read the jar file? Is there some other way of specifying resources in java webstart other then .jar files? So maybe I could
specify the xmltest.xml file in the jnlp?

You can put the xml file in the jar, but you need to use getResource() to fetch it


            java.net.URL url = getClass().getResource("xmltest.xml");

Use the URL to open a stream and you’re off :slight_smile:

just wondering how would you go about this from a static method? since getClass() doesn’t work…

i’ve worked around this by creating a new instance of a small class i had in my JAR and calling getClass() on it… it works, just seems a bit messy…

Actuall getClass().getResource() isn’t recommended anymore for some reason.


Thread.currentThread().getContextClassLoader().getResource("your resource here");

is apparantly the right way. That should also work from static contexts.

Kev