Getting resources from dynamically loaded jar

Hi. I’m doing the JOGL demo box where you can press a list of demo jars and have them dynamically loaded and displayed in a window.

My problem is that from inside these jars I can’t load the resources unless they are in the same dir as the JOGL demo box application.

I get my stream like this:


// Attempt load from jar file
                URL fileURL = new URL("jar:file:" + jarName + "!/"+filePath);
                JarURLConnection jarConnection = (JarURLConnection)fileURL.openConnection();
                is = jarConnection.getInputStream();

I realise why it only works from the same path as the application that loads the jar, but I don’t know how I can get a resource from inside the dynamically loaded jar, since the classloader comes from the main application.

Anyone knows how this is done? (Simply solution please. I don’t want to open a real jar stream and sift through the entries etc. etc. if can help it. And I would’t know how to find it anyway :))

This link can be of interest

http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=OnLin;action=display;num=1089334183;start=3#3

I don’t download the jar only load them from a directory. But it is basicly the same thing.

Thanks. I am a moron. Figured it out just after writing here :slight_smile:
I was a simple cut and paste bug so I was getting resources from the context class loader from the active thread, instead of this.getClass().getClassLoader().getResource();

;D