-
1. Re: Bug (?) wrt. getResourceAsStream() from webapp component
chgrimm Oct 1, 2002 2:27 AM (in response to adrians)could you send me ear with a simple example ( war file + common.jar containing resources )
i have the source distro of jboss 3.0.2. may be i can figure out via debug -
2. Re: Bug (?) wrt. getResourceAsStream() from webapp component
adrian.brock Oct 1, 2002 3:50 AM (in response to adrians)getResourceAsStream("resource.xml");
Regards,
Adrian -
3. Re: Bug (?) wrt. getResourceAsStream() from webapp component
adrians Oct 3, 2002 2:28 PM (in response to adrians)> getResourceAsStream("resource.xml");
>
> Regards,
> Adrian
Thanks, this seems to work. Why is it that by prefixing the resource with a "/" it fails to work, though? I thought the convention for looking from the top of the classloader's namespace was to prefix a resource in this manner. As a point of note, Weblogic succeeds in loading a resource from the root of the namespace with or without the "/" through the getResourceAsStream() call on a classloader. Someone might consider changing this behaviour in order to make life easier for people switching to JBoss from Weblogic.
Adrian -
4. Re: Bug (?) wrt. getResourceAsStream() from webapp component
adrian.brock Oct 3, 2002 11:16 PM (in response to adrians)Which convention?
I think this is a "feature" of the weblogic classloaders.
Try it from a simple java class with a resource inside
a jar on your classpath.
Doesn't work then either.
Regards,
Adrian -
5. Re: Bug (?) wrt. getResourceAsStream() from webapp component
adrians Oct 4, 2002 12:22 PM (in response to adrians)Adrian,
From the javadoc for Class getResourceAsStream:
---
Finds a resource with a given name. This method returns null if no resource with this name is found. The rules for searching resources associated with a given class are implemented by the defining class loader of the class.
This method delegates the call to its class loader, after making these changes to the resource name: if the resource name starts with "/", it is unchanged; otherwise, the package name is prepended to the resource name after converting "." to "/". If this object was loaded by the bootstrap loader, the call is delegated to ClassLoader.getSystemResourceAsStream.
---
The ClassLoader getResourceAsStream() refers to getResource() for details and that method saysthe following:
---
This method will first search the parent class loader for the resource; if the parent is null the path of the class loader built-in to the virtual machine is searched. That failing, this method will call findResource to find the resource.
---
The way I read it, the ClassLoader getResourceAsStream() should be able to handle resource names prefixed with "/" as referring to resources at the root of the namespace since the Class method will delegate to it. Also, resources could possibly end up being loaded through either the Class or ClassLoader methods in a given app and my feeling is you shouldn't need to have two different string defined depending on the expected use. What I mean (this answers your second point) is that if you have a resource that exists at the root but whose path is defined without the leading "/" and you try to load it through the Class getResourceAsStream() it would not be found since it would be prefixed with the respective class' package. Anyhow, that's my take on it...
Adrian2 -
6. Re: Bug (?) wrt. getResourceAsStream() from webapp component
adrian.brock Oct 4, 2002 4:21 PM (in response to adrians)Yes,
getClass().getResourceAsStream("/resource.xml");
works as described in the javadoc.
If you look at the code for java.lang.Class
it passes "resource.xml" to the classloader.
Regards,
Adrian