Re: how to set image path
To: comp.lang.java.gui
marcussilfver@gmail.com wrote:
Also, consider using getClass().getResource(). It has a slightly
different way to search for resources compared to
getClass().getClassLoader().getResource() when the resource name
starts with "/". This "absolute" way to search for resources is often
what you want.
Thanks for answering.
I must use relative paths, my resource names does not start with "/".
I may not have been all that clear in my previous post.
The resources should have been copied into
the target (class directory or jar).
I can not put the resources in my class directory, since I use Jigloo
GUI builder which dont allow me to specify images in other directories
but the "src" directory or subfolders of it. When running my app the
JVM looks in the bin folder for the image.
my directory hierarchy looks like this:
myProject
bin
myapp_classes // classes generated from my java source by
Eclipse
images // these images are found by JVM, but not by
Jigloo
src
myapp_src // my java source code
images // these images are found by Jigloo, but not by
JVM
So right now I have 2 folders named "images" containing all my images.
One is placed as a subfolder of the bin folder and the other is placed
as a subfolder of the src folder. The content of the images folders
are identical.
If I delete the bin/images/ folder then the image will not be found at
runtime, they will be found by Jigloo though.
If I instead deletes the src/images/ folder then no image will be seen
in Jigloo, they will be found at runtime though.
What can I do to make JVM and Jigloo use the same path for images? I
see 2 solutions to this:
1) have 2 "images" directories (like my current solution)
2) have both .class files and .java files on the class path, like
MyProject
src
myapp_src_and_classes
images
Any other ideas on the best way to solve this?
I'm not sure what the ideal solution would be. Probably to use ant to create a
distribution jar containing the classes and the images, and then run that.
One less than ideal solution, if this is Linux or UNIX as the path names appear
to be, would be to either hard or symbolic link the two image directories. At
least that way you would only have one actual image directory, with the other
being a link to it. There would only be one copy of each image, and only one
directory to maintain.
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24