> My directory contains the files Test.java and Test.class. At Runtime, I
> get a NullPointerException pointing to the line:
>
> String currentDir = Test.class.getResource("Test").getPath();
Thanks Ingo. That fixed my problem. Finally have it working!! Never
thought of explicitly naming the file!
I also tried this out with one of my files packaged in a .jar, nested
in the Tomcat directory structure.
Curiously, the path I get is prefixed by "file:" i.e. something like
"file:\C:\Program Files\.....\Tomcat\webapps\commonfiles"
is it because this is getting executed from c:\win32 rather than the
actual location?
This doesn't seem to be causing any problems - windows seems to
understand it well. but if i were to deploy on Unix, that would mean
trouble.
when I tried the earlier example with "Test.java" and ran from the
container directory for Test.java, I got the path without the "file:\"
prefix?..
> Hi,
>
[quoted text clipped - 15 lines]
> Ciao,
> Ingo
Andrew Thompson - 29 Sep 2005 11:06 GMT
> Thanks Ingo. That fixed my problem. Finally have it working!! Never
> thought of explicitly naming the file!
[quoted text clipped - 7 lines]
> is it because this is getting executed from c:\win32 rather than the
> actual location?
?
> This doesn't seem to be causing any problems - windows seems to
> understand it well. but if i were to deploy on Unix, that would mean
> trouble.
No trouble at all. So long as the resource is found, it
will return a valid URL that points to the resource.
You might note that your resources in .jar archives will
have a '!' after the jar name to indicate the resource was
found inside a jar, rather than an oddly named directory.