Hi,
getResource will find the files provided they are inside a jar in the
classpath, or a directory in the classpath.
You don't have to tell getResource whether it should look for a jar archive
or in directories.
It will return the first one it finds in its classpath .
Whether you run your app from a jar or not, makes no difference to this.
You just have to ensure that a given resource (with its relative path)
cannot be found at two different places in the classpath (say, remove those
from the jar to be sure that the filesystem's ones will be found).
Arnaud
> I've got a kuhl application that among other things, for a demo,
> flashes pictures, meant to look like a top-down view of a map,
[quoted text clipped - 6 lines]
>
> if ( ae.getSource() ==
EvwfConstantButtons.buttonElementArray[EvwfConstantButtons.PBC_REFRESH_MAP_B
UTTON])
> {
>
[quoted text clipped - 45 lines]
>
> Refreshed Map URL is:
jar:file:/home/rooty/java/EastValleyWaterForumInterface/evwfLocal.jar!/edu/a
su/dt/evwf/images/EvwfSampleMap2.png
> Refreshed Map URL is:
jar:file:/home/rooty/java/EastValleyWaterForumInterface/evwfLocal.jar!/edu/a
su/dt/evwf/images/EvwfSampleMap1.png
> The same code, running not from the jar file, found them here, in
> normal, non-jar-archive relative file path names, converted to full
> ones, instead:
>
> Refreshed Map URL is:
file:/home/rooty/java/EastValleyWaterForumInterface/edu/asu/dt/evwf/images/EvwfSampleMap2.png
> Refreshed Map URL is:
file:/home/rooty/java/EastValleyWaterForumInterface/edu/asu/dt/evwf/images/EvwfSampleMap1.png
> But now, I want to _run from_ the jar, but _access files_ (the real
> map data this time, being updated by an independent process from
[quoted text clipped - 6 lines]
>
> xanthian.
Kent Paul Dolan - 27 Jan 2006 18:18 GMT
> KPD wrote:
>> But now, I want to _run from_ the jar, but _access files_ (the real
>> map data this time, being updated by an independent process from
>> outside my control) from a non-jar directory relative to the one in
>> which the jar file sits.
>> How do I convince java.net.URL (or more correctly the
>> EvwfUtilities.class.getResource( String dataRelativeLocation )
>> calls) to do that?
> getResource will find the files provided they are inside a jar in the
> classpath, or a directory in the classpath.
> You don't have to tell getResource whether it should look for a jar archive
> or in directories.
> It will return the first one it finds in its classpath .
> Whether you run your app from a jar or not, makes no difference to this.
> You just have to ensure that a given resource (with its relative path)
> cannot be found at two different places in the classpath (say, remove those
> from the jar to be sure that the filesystem's ones will be found).
Ah, the insights one fails to gain from laziness. I've now written
megabytes
of Java source code without ever once assigning a classpath. So, just
avoiding
namespace collisions in what getResource treats as an inherently
ambiguous
file system between that internal to a jar and a possible (very likely,
really)
identical filesystem directory layout parallel with that within the jar
does the trick!
Who'd have guessed!?!
Thanks for the help!
xanthian.