Re: protocol question
- From: "Rhino" <no.offline.contact.please@xxxxxxxxxx>
- Date: Sun, 30 Oct 2005 12:22:40 -0500
"Thomas Fritsch" <i.dont.like.spam@xxxxxxxxxxx> wrote in message
news:dk1arj$cro$01$1@xxxxxxxxxxxxxxxxxxxx
> "Rhino" <no.offline.contact.please@xxxxxxxxxx> wrote:
> > I've been using the Jar: protocol a bit in the last few days and I'd
like
> > to know if this is a valid use of that protocol:
> >
> > jar:file:!/Images/foo.gif
> AFAIK the JAR-URL-specification requires the part between "jar:" and "!"
to
> be a valid URL, i.e. the URL of the jar file. In your case this part is
> "file:" which surely is invalid. Hence, in my opinion it would be a
mis-use
> of the "jar:" protocol.
> >
> > Basically, I'm trying to describe the location of a GIF that a program
> > should be able to find in one of the various jars that are on the
> > classpath
> > used by the program.
> >
> > Since 'this.getClass().getResource()' will search EVERY jar in the
> > classpath
> > for the desired file, it shouldn't be necessary to specify the jar name.
> > Therefore, it seems to me that this should be valid notation for
> > indicating
> > that the jar name isn't necessary in this case: the bang ('!') in the
name
> > following the 'file:' suggests to me that the default jar(s), namely all
> > of
> > the jars found in the classpath, will be searched for an Images
directory
> > and a file named foo.gif within that directory.
> >
> > Does that seem reasonable? If not, can anyone suggest a better notation
to
> > use for my situation?
> Yes, sure. It is a reasonable thing to want.
> But I would suggest not to use the "jar:" protocol, and instead prefer to
> invent a new
> protocol (the name "classpath:" comes to mind). Example URLs might then
be:
> classpath:/Images/foo.gif
> classpath:/javax/swing/plaf/metal/icons/Error.gif
>
> You can push this approach even one step further. If you would write a
small
> Handler for this new protocol, then you could use your new URLs exactly
like
> any other URL. For example:
> URL url = new URL("classpath:/Images/foo.gif");
> InputStream stream = url.openStream();
> More on protocol handlers can be found at
>
http://java.sun.com/j2se/1.4.2/docs/api/java/net/URL.html#constructor_detail
I think I like your proposal! It seemed reasonable to me to continue to use
the 'jar:file:', since it seems to be acceptable to use
'jar:file:c:\\myJars\\big.jar!/Images/foo.gif' to designate a specific entry
within a jar on the filesystem. After all, a jar on the classpath is also on
the filesystem, by definition. But using a new protocol like your proposed
'classpath:' is clearer than trying to use 'file:' within 'jar:'.
The downside is that no 'classpath:' protocol is known to anyone but you and
me, at least as far as i know. That means it may raise more questions than
it solves if anyone else sees my code. Of course, I could approach whatever
body creates RFCs and suggest the creation of a 'classpath:' protocol but
that strikes me as a process that would drag on for years. Still, that is
probably the best solution from a design point of view....
> >
> > I can't find any discussion of this "special case" in the articles I've
> > seen
> > about the Jar: protocol.
> >
>
Rhino
.
- References:
- Jar: protocol question
- From: Rhino
- Re: protocol question
- From: Thomas Fritsch
- Jar: protocol question
- Prev by Date: Re: Animation jargon
- Next by Date: Re: protocol question
- Previous by thread: Re: protocol question
- Next by thread: Re: Jar: protocol question
- Index(es):
Relevant Pages
|