Re: Re: Re: enhancement request for Ant event builder task
Jacob Kjome <[email protected]>
| Newsgroups | gmane.comp.java.enhydra.barracuda.general |
|---|---|
| Message-ID | <[email protected]> |
That's interesting because in my experience, if you have a file in the same
package as the class loading the file, you can do this...
getClass().getResourceAsStream("myfile.txt");
that will load successfully. However, if "myfile.txt" is in the root
package, it will not be found. To find it using the above, one needs to do...
getClass().getResourceAsStream("/myfile.txt");
The equivalents to the above (again, in my experience) using the
classloader (assuming a package of org.mypackage) is, respectively...
getClass().getClassLoader().getResourceAsStream("org/mypackage/myfile.txt");
and
getClass().getClassLoader().getResourceAsStream("myfile.txt");
But, if you say it works and have tested this, then I have no problem with
it. And I'll just change the tabs to spaces on my end.
thanks for the patch!
Jake
At 07:19 PM 9/16/2003 +0200, you wrote:
>Jacob Kjome <[email protected]> wrote:
>
> > I've never actually bothered to use the "template" attribute of the
> > <build-events> tag.
>And I even think you didn't used another template at all, because of your
>Barracuda leadership ;-)
>
> > What have you used as a sample value for the "template"
> > attribute? Is it a fully qualified path to the file from the root of
> > the classloader such as?...
>On my tests I used a relative path, ergo not starting with "/" and it
>worked. If you view the implementation of Class.getResourceAsStream() method
>(Java 1.4.1):
>
>public InputStream getResourceAsStream(String name) {
> name = resolveName(name);
> ClassLoader cl = getClassLoader0();
> if (cl==null) {
> // A system class.
> return ClassLoader.getSystemResourceAsStream(name);
> }
> return cl.getResourceAsStream(name);
>}
>
>... as you see, there is a simple delegation to the classloader.
>Additionally the Java doc says:
>* <p> 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
>* <code>ClassLoader.getSystemResourceAsStream</code>.
>
>So:
>
>getClass().getResourceAsStream(cs.template)
>getClass().getClassLoader().getResourceAsStream(cs.template)
>
>... is pretty the same.
>
>
> > Oh, and try to make sure you use spaces instead of tabs with
> > a 4 spaces indentation.
>Sorry, I always use tabs for indentation and was too lazy to alter the IDE
>configuration only for this.
>
>
>Thorsten
>
>_______________________________________________
>Barracuda mailing list
>[email protected]
>http://barracudamvc.org/lists/listinfo/barracuda