Rebirth problem (Orangy Tang)

I am getting an exception when trying to find the reousrce file:


Couldn't open from file, trying classpath (java.io.FileNotFoundException: \data\resources.xml (The system cannot find the path specified))
Couldn't open stream for 'resources.xml' from either file system or classpath (base dir is '/data')
Couldn't open 'resources.xml' from either file system or classpath (base dir is '/data')
java.net.MalformedURLException
	at java.net.URL.<init>(URL.java:601)
	at java.net.URL.<init>(URL.java:464)
	at java.net.URL.<init>(URL.java:413)
	at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:650)
	at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:186)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
	at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
	at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
	at com.triangularpixels.rebirth.resources.ResourceParser.parse(ResourceParser.java:58)
	at com.triangularpixels.rebirth.resources.ResourcePool.parse(ResourcePool.java:60)
	at com.seige.SeigeResources.getResourcePool(SeigeResources.java:19)
	at com.seige.Seige.initStatesList(Seige.java:29)
	at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:157)
	at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:390)
	at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:314)
	at com.seige.Seige.main(Seige.java:40)

Here is the line of code:


            resources = Resources.createPool("/data", Resources.DecoderGroup.CORE, true);
            resources.parse("resources.xml");

I have tried “/data” and “data” an neither works. I have the data directory at the root of my src directory like this:
src
|–com
| |—seige
|
|–data
|–images
|–resources.xml

I would look at it myself, but the source isn’t available yet.

Any thoughts?

Thanks.

Hey I made a game named Siege once. :slight_smile: It was a networked multiplayer rampart clone.
http://n4te.com/dev/games/siege-0.5.zip
http://n4te.com/dev/games/siege-0.5-src.zip

maybe this:

resources = Resources.createPool("/data", Resources.DecoderGroup.CORE, true);
resources.parse("resources.xml");

should be:

resources = Resources.createPool("data", Resources.DecoderGroup.CORE, true);
resources.parse("resources.xml");

btw:
“/data” is an absolute path

So that’s not it.

Well, so don’t you simply print the workdir?
System.out.println(new File("."));
To see whether it matches your expectations.

I generally leave the leading / off as it can cause problems, so the example with “data” is correct. However I suspect that’s not your issue here.

Basically resource files can either be fetched from the file system directly (via File) or via the classpath (via getResourceAsStream()). But the ‘baseDir’ is only used when loading from the file system. So when you load ‘resources.xml’ trying to open “data/resources.xml” from the file system, and if that fails it tried ‘resources.xml’ from the classpath.

So I think you need to either specify the base dir as “src/data” or put ‘src/data’ on the classpath. The first is preferred, as it’ll watch files for modifications. At deployment time you’d turn your src/data directory into a data.jar and it’s load the contents of the classpath.

Hope that helps, it’s tricky to explain in text so I should probably put a clearer explanation in the documentation.

Thanks, that was the problem.

I thought the baseDir was always appended. I wanted it to find resources.xml on the classpath and thought it would append data to the getResourceAsStream() call.

I changed it and it works now.

Yeah, I should probably adjust the docs to be clearer (even if it’ll be somewhat more verbose).

I would recommend that for development you have it load the files from the file system though, as that way it’ll monitor file timestamps and reload any changed xml files for you on the fly (which it can’t do if files are loaded from the classpath since you can’t get timestamp info).

Do you know what you’ll be using the system for? Heavyweight resources like images/sounds/etc. or lightweight stuff like enemy movement properties and other gameplay shenanigans?

Not yet. I just started to try it out to see what it could do.

I was hoping it could provide image loading/management too.

Yeah, it should work fine for images. You can even use the FileMonitor passed to a Resource to get callbacks when your image file has been modified so you can reload it (which makes development so much nicer :slight_smile: ).

The ultimate goal would be to somehow be notified of changes to individual elements of XML without accidentally reloading 50 unchanged resources…

Cas :slight_smile:

Yeah, that’s a little tricky though, and since reloading is a debug feature I’m not too concerned about the speed. Unless it’s causing you other problems?

I suppose I could store a hash of the xml used to generate each resource, but I’m not entirely sure a hash of a single xml element could be generated in a quick and efficient way.

It shouldn’t be too hard to hash an element I think. But I suppose the really difficult bit is the efficient detection of a change to a single bit of XML and then only touching the dependencies as well.

Cas :slight_smile: