• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help! findResource isn't working!

 
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
reply
    Bookmark Topic Watch Topic
  • New Topic