Help! findResource isn't working!

I'm at a complete loss. In my classloader, I print out all the URLs of the ClassLoader (which extends URLClassLoader). When it prints them out, one of the URLs is:file://D:/Resources/Factory.cfg However, when I call classLoader.findResource( "Factory.cfg" ), it returns null. In fact, I even put the below code in (to be sure it wasn't a security issue):

In my classloader, I print out all the URLs of the ClassLoader How do you do this, exactly? What if you try

or

? These may not be the forms you want to use in the long run, but if one of these returns a result, it can give a clue what the problem is. Are you using a custom class loader here? Does it override findResource() or any similar method? Does the class loader have a parent loader, or is it null? [ March 01, 2004: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister

Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585

posted Mar 01, 2004 22:05:00

0

OK, I found the reason why it's not working and maybe you can explain to me the thinking behind this. Apparently if I add the URL: "file:/d:/resources/factory.cfg" it cannot find the resource "factory.cfg". However, if I add the URL: "file:/d:/resources/" then it CAN find "factory.cfg". Why is it set up to only be able to find a file in a jar or a folder? I don't understand why URLClassLoader cannot figure out that "file:/d:/resources/factory.cfg" is referring to a file or resource named "factory.cfg". Am I doing something wrong here? (I did not create the URL myself, instead it was added to the classpath by ant and then the System classloader created a URL for it).