Re: protocol question




"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


.



Relevant Pages

  • Re: protocol question
    ... > to know if this is a valid use of that protocol: ... i.e. the URL of the jar file. ... More on protocol handlers can be found at ...
    (comp.lang.java.programmer)
  • Jar: protocol question
    ... I've been using the Jar: protocol a bit in the last few days and I'd like to ... Since 'this.getClass.getResource' will search EVERY jar in the classpath ... so simple that there are obviously no deficiencies. ...
    (comp.lang.java.programmer)
  • Re: how to set up a simple plugin mechanism
    ... > relevant classes or a list of names from which the relevant class ... > classpath or in some jar. ... WhatEverPlugin interface, and if they do I load them. ...
    (comp.lang.java.help)
  • Re: Suchreihenfolge =?ISO-8859-15?Q?f=FCr?= CLASS-Files
    ... Umgebungsvariable CLASSPATH eine aus einem JAR bestehende Anwendung ... Zielrechner eine alte Version meiner Bibliotheken installiert habe und im ... einer fremden Maschine alles installiert hat (meist nur die JVM mit ...
    (de.comp.lang.java)
  • Re: Java on VMS
    ... Maybe you just need to put a missing jar file in WEB-INF/lib. ... I have had some issues with getting jars to show on the classpath, ... I'm no VMS pro so I'm not entirely sure ...
    (comp.os.vms)