[VFS] classpath lookup for opaque JAR

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[VFS] classpath lookup for opaque JAR

Philippe Poulard
hi,

i'm still using VFS, and I'm working rigth now with jar resources

an URI like this :
jar:myJar.jar!/path/to/resource
will work, whereas when using traditional java.net.URL parser it fails
because such URI is opaque

fine !

however, the URI is resolved like this :
jar:file:///path/to/current/dir/myJar.jar!/path/to/resource

mmmh, I would prefer that instead endorsing the current dir, it would
lookup in the classpath for the library that has this name

any advice ?
--
Cordialement,

            ///
           (. .)
  -----ooO--(_)--Ooo-----
|   Philippe Poulard    |
  -----------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [VFS] classpath lookup for opaque JAR

Mario Ivankovits
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [VFS] classpath lookup for opaque JAR

Philippe Poulard
Mario Ivankovits wrote:

> 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 "/"

Great ! This is exaclty what I was looking for

>
> This will search the resource using javas default
> ClassLoader.getResource(name)
>
> However, once resolved it will be expanded to its full location.

That's not a problem

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

Sure
I'll try all the stuff and report troubles, if any

thanks

--
Cordialement,

            ///
           (. .)
  -----ooO--(_)--Ooo-----
|   Philippe Poulard    |
  -----------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]