Re: protocol question



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.
.



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: 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)
  • Re: FatJar Exporter
    ... > Ich Vermute im Classpath befindet sich eine JAR Datei in zwei ... > da dort beide Jars jeweils ihr eigenes Manifest haben. ... > Welche Probleme gibt es bei der Verwendung von One-Jar? ... Next by Date: ...
    (de.comp.lang.java)