Re: protocol question
- From: Roedy Green <my_email_is_posted_on_my_website@xxxxxxxxxxxxxx>
- Date: Sun, 30 Oct 2005 06:08:08 GMT
On Sat, 29 Oct 2005 13:11:04 -0400, "Rhino"
<no.offline.contact.please@xxxxxxxxxx> wrote, quoted or indirectly
quoted someone who said :
>I'm looking for a notation that I can use in my programs to refer to files
>that are within jars that are visible to the program by virtue of being on
>the program's classpath. In that case, the name of the jar isn't necessary
>since all jars in the classpath will be scanned for the file. That's why I
>was thinking that 'jar:file:!/images/foo.png' would be good since it
>imitates the first example and implies that the file is in the file system
>but that we don't care what jar contains the file.
getResource does searching and gives you the FIRST resource match on
the classpath.
It produces the !syntax which is treated thereafter like any other
URL.
You want a method something like this off the top of my head:
/**
@param s either resource or URL to resource
code either as "myimage.jpg"
or as "jar:file:///C|/bar/baz.jar!/com/foo/myimage.jpg"
@eturn URL to resource
*/
getURLForResource( Class c, String s )
{
if ( s.startsWith( "jar:" )
|| s.startsWith( "file:" )
|| s.startsWith( "http:" ) )
return new URL( s );
else return c.getResource( s );
}
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
.
- Follow-Ups:
- Re: protocol question
- From: Rhino
- Re: protocol question
- References:
- Jar: protocol question
- From: Rhino
- Re: protocol question
- From: Ben_
- Jar: protocol question
- Prev by Date: Re: Jar: protocol question
- Next by Date: Re: protocol question
- Previous by thread: Re: protocol question
- Next by thread: Re: protocol question
- Index(es):
Relevant Pages
|