File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help! findResource isn't working!

 
Robert Paris
Ranch Hand
Posts: 585
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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).
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic