Loading image from jars from other jars etc

J

JavaEnquirer

I have no problems loading an image from a jar using a class which
shares that jar. However, if I have a utility jar which contains a
ImageLoader utility class and use this class from my main application
jar which contains the images, I get a null pointer exception on
createImage.
( I'm using the utility class's class loader and calling the get
resource method. ) I don't get a problem running my application
jar-less in Eclipse.

When I got this error I assumed that by default you can only load a
resource from the same jar. So, I put the images into the utility jar
too, but to no avail - the same error.

Anyone got any pointers? Is there a way of loading resources from other
jars as I'm trying to do?

many thanks in advance.
 
J

JavaEnquirer

I've just tried passing the class loader of the application ( whose jar
contains the images ) to the ImageLoader class in the utility jar for
it to use. This doesn't seem to work either. Is there any mileage in
looking at the URLClassLoader class?
 
J

JavaEnquirer

I've come across a suggestion that I ensure that my application.jar is
included in the class path of my utility.jar. This way, the ImageLoader
in utility.jar can load images from application.jar as requested by
application.jar. I'd like to avoid this as utility jars shouldn't be
coupled to code that may call them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top