Re: protocol question




"Roedy Green" <my_email_is_posted_on_my_website@xxxxxxxxxxxxxx> wrote in
message news:b7o8m1dvi0k9f7qvar5jqrj8n5a62u3h5t@xxxxxxxxxx
> 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 );
> }

You might be on to something there! Hmm, let me think that over a bit....

Rhino


.



Relevant Pages

  • Re: protocol question
    ... >since all jars in the classpath will be scanned for the file. ... getResource does searching and gives you the FIRST resource match on ...
    (comp.lang.java.programmer)
  • Re: path to ant; ant launcher
    ... ..ant folder in /home/thufir. ... [thufir@localhost java]$ ant ... 153 # Build local classpath using just the launcher in non-rpm mode ... 158 # request optional jars and their dependencies via the ...
    (comp.lang.java.help)
  • Re: netbeans doesnt create lib directory under dist
    ... Under those circumstances I could just keep appending jars ... NetBeans ties pieces together according to a different set of rules. ... NetBeans communicates the CLASSPATH some other way. ... and only the Class-Path: in the manifest prevails. ...
    (comp.lang.java.programmer)
  • Re: Setting up a classpath only for junit test.
    ... I have set a classpath element entry (in .classpath file for my ... resource is found correctly. ... would specify the location of resource-name2, ... only within "the scope" of junit tests. ...
    (comp.lang.java.programmer)
  • Re: Accessing external jar from servlet
    ... > classpath variable doesn't help Tomcat to find the library, ... Within this directory are, among other things, a classes directory ... The lib directory is where JARs go. ... application's WEB-INF/lib to gain access to it. ...
    (comp.lang.java.help)