You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Greg Reddin <gr...@fnf.com> on 2005/07/29 18:14:32 UTC
[tiles] getResourceAsStream question
I was working on some test cases for standalone Tiles and the following
code in I18nFactorySet was not behaving as I expected:
// If the config isn't in the servlet context, try the class
loader
// which allows the config files to be stored in a jar
if (input == null) {
input = getClass().getResourceAsStream(filename);
}
"input" was being returned as null in that case. When I changed it to
the following it worked:
// If the config isn't in the servlet context, try the class
loader
// which allows the config files to be stored in a jar
if (input == null) {
ClassLoader cl = this.getClass().getClassLoader();
input = cl.getResourceAsStream(filename);
}
Why would it make any difference whether I reference the ClassLoader or
not? I noticed a couple other places where getResourceAsStream() is
called from the class instead of the ClassLoader as well (in the Struts
mock objects). Is there a reason why the class is preferred? Aren't
they really doing the same thing?
BTW, I understand that in production that code would not likely be
called because the config file would be returned from the servlet
context.
For reference I'm using JDK 1.4.2 on Mac OSX 10.3. I got the same
results running the test target from within NetBeans 4.1 and the
command line. I didn't try it on Linux to see if it yielded different
results.
Thanks,
Greg
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org