Redbeard wrote:
> On May 6, 11:02 pm, Roedy Green <see_webs...@[EMAIL PROTECTED]
>
> wrote:
>> On Tue, 6 May 2008 11:41:07 -0700 (PDT), cowde...@[EMAIL PROTECTED]
>> wrote, quoted or indirectly quoted someone who said :
>>
>> >While I'm certainly no expert, I'm also not a novice. I've written
>> >several apps and gotten them to work in a jar, but none had images in
>> >them. And I can get this app to run from the jar (depending on what
>> >code I have used), but I can't get the images to work.
>>
>> I understood from you earlier post you could not get a jar to execute
>> at all. Apparently it executed but crapped out as soon as it came
>> time to deal with the image.
>> --
>>
>> Roedy Green Canadian Mind Products
>> The Java Glossaryhttp://mindprod.com
>
> Sorry for the confusion. Apparently, I wasn't as clear as I thought I
> was.
>
> Before I posted, I had researched and tried a variety of different
> ways to load the images. They all worked from the class files, but
> none would load the images once I jarred everything up. Most of the
> time the jar file would execute, but not have images. However, SOME
> techniques actually kept the jar file from executing - or more likely
> - caused it to hang before anything became visible.
>
> I was sure I was making some small mistake that I just couldn't see -
> which is why I posted. I see now that my problem was that I was using
> the relative path rather than the absolute path. Obviously, I have
> more to learn about that. I'd read about absolute vs. relative paths
> and thought that relative was the way to go.
It's not that you were using a relative path, relative paths are perfectly
ok
and it may be argued that they are the preferred method. The problem is
most
likely that you were using the wrong relative path. There is only one
absolute
path, and that path is independent of the object you use as the basis of
the
getClass().getResource(). There are a large number of relative paths you
might
use, and each is dependent on where you base the relative path.
For a relative path the origin is the directory containing the class which
is
returned by getClass(). You need to base your relative path in
getResource()
from that directory. Don't forget that the jar has a directory structure
based
on the package structure of the class definitions.
--
Nigel Wade


|