One last problem :) (URL and ressources)


i have one last problem with my application. i use those lines to add a resource to my terrain:

URL monkeyLoc;
monkeyLoc = CP_Controller.class.getClassLoader().getResource("data/Grid.png");

this works great if i run my project with eclipse. but if i build the project with fatjar/onejar and try to run the application, the texture can't be found even the file is in the directory data/grid.png.

does anybody know how to fix that?

would be a great help! thx

this should work in eclipse and jar

           new SimpleResourceLocator(CP_Controller.class.getClassLoader().getResource("data/")));

URL monkeyLoc= (URL) ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "Grid.png");

hi thx for your help, but unfortunately that doesn't work in fatjar :frowning:

does anybody know how the properties.cfg file is loaded? because this file is found by fatjar

an again a post from me sry:

i found a way that it works on fatjar but not with eclipse. is it somehow possible to detect how the application was started?

in eclipse this works:

URL monkeyLoc = CP_Controller.class.getClassLoader().getRessource("data/grid.png");
Texture t = TextureManager.loadTexture(monkeyLoc, Texture.MM_Linera, Texture.FM_Linear);

but in fatjar this works:

Texture t = TextureManager.loadTexture("data/grid.png", Texture.MM_Linear, Texture.FM_Linear);

In a recent runaround with this sort of thing, I found that the solution (to run from Eclipse, FatJar, and WebStart) was to skip the last slash on texture resources and include the slash on model resources (I don't know about the other types).  I have not looked at the code yet to see why this might be the case.  So, the following appears to work for all cases (at least with what I'm working with):

           new SimpleResourceLocator(CP_Controller.class.getClassLoader().getResource("package/assets")));

           new SimpleResourceLocator(CP_Controller.class.getClassLoader().getResource("package/assets/")));

strange, maybe the resourcelocator could be improved to be a bit more flexible with those slashes