How to use a folder of a jar (or zip) file for ResourceLocator

Hello,

I would like to use a folder of a jar (or zip) file as ressource folder using :



URI uri= new URI("file:///D:/temp/data.jar!/texture/");      
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,new SimpleResourceLocator(uri));


But I need the correct way to write it.

Thank you for your help.

OK I found :



URI uri = new URI("jar:file:/D:/tmp/data.zip!/textures/test.txt");
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,new SimpleResourceLocator(uri));


Thats not a bad way to explicitly define the file you want, but an easier way might be to use

Thread.currentThread().getContextClassLoader().getResource("path_here")



(that will include the Jar stuff right into the path for you :), and I think it does work for zip files...)

OK thanks,

but my problem was actually in this : "path_here".

I didn't know how to specify the right path, in order to indicate a folder in a jar file.

with that you just have to supply the path inside the jar file and the rest will be 'tacked' on…



Example:


URL url = Thread.currentThread().getContextClassLoader().getResource( "textures/test.txt" );



Would return a URL equal to:


jar:file:/D:/tmp/data.zip!/textures/test.txt

Really?

I have to specify that the jar or zip file is an extern file.

I guess there was a tidbit I forgot to mention, in order for that to work the zip or jar file must be included in the classpath.



You solution will work even if the archive is not in the classpath; however defining absolute paths like that places the burden of keeping track of where the 'root' location is on you.

OK thanks anyway for your help.