commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mario Ivankovits <ma...@ops.co.at>
Subject Re: [VFS] classpath lookup for opaque JAR
Date Wed, 18 May 2005 07:20:10 GMT
Philippe Poulard wrote:
> an URI like this :
> jar:myJar.jar!/path/to/resource
> is resolved like this :
> jar:file:///path/to/current/dir/myJar.jar!/path/to/resource
>
> I would prefer that instead endorsing the current dir, it would lookup 
> in the classpath for the library that has this name
If you would like to access a resource within a jar which is in your 
classpath you could use

res:path/to/resource

notice the missing starting "/"

This will search the resource using javas default 
ClassLoader.getResource(name)

However, once resolved it will be expanded to its full location.
e.g. wenn you search for

res:META-INF

you might get

jar:file:///usr/java/jdk1.5.0_03/jre/lib/rt.jar!/META-INF

You cant directly specify the jar filename where this META-INF should be 
sourced.

If you have a special directory where you place your jars and put THIS 
directory in your classpath (e.g. /path/to/my/jars) then it should be 
possible to use

FileObject fo = VFS.getMananger.resolveFile("res:anyjar.jar");
FileObject root = VFS.getManager().createFileSystem(fo);

due to a bug in VFS you cant use "jar:res:anyjar.jar!/" - but this will 
be fixed.


But notice the difference:
The first will lookup the resource in any jar/path on your classpath as 
it is intended by the java ClassLoader.getResource.
The second is a "hack" to specify exactly which jar should be used. You 
might get problems whith such a solution as in an webapp the WEB-INF/lib 
directory is NOT in your classpath and you cant manage to get it in 
there (as far as I know). But I think its the first solution you looked 
for, isnt it?


---
Mario


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message