wood burning stoves*
The moose likes Java in General and the fly likes Help! findResource isn't working! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Help! findResource isn Watch "Help! findResource isn New topic
Author

Help! findResource isn't working!

Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
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):

Still null!! Any idea what I'm doing wrong?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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
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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help! findResource isn't working!
 
Similar Threads
Loading POJO object without loading library first
Please Help! I'm going crazy! Classloader problem
Stumped on classloading problem! Help!
String literals and memory.
Why getting ClassCastException?