Referencing a file in the same folder as my programs jar.

I have some images that my application uses and am having a very hard time figuring out how to best reference them. I want it so that my program can be anywhere on the HD as long as it's in one folder. The problem with this is that when I try and reference my images using just the image name, it seems to assume that the user is starting from their home directory. I need a way to make a relative reference to the images in the same directory as my program.

Any ideas?

[483 byte] By [nehalema] at [2007-11-27 5:31:46]
# 1
Put them all in a jar and get them as resources...[url= http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html#getResource(java.lang.String)] http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html#getResource(java.lang.String)[/url]
kevjavaa at 2007-7-12 14:57:19 > top of Java-index,Java Essentials,Java Programming...
# 2
I have tried this but not in the same way you are saying to. Any better examples on doing that? That documentation is a bit cryptic to me (a new programmer in java).
nehalema at 2007-7-12 14:57:19 > top of Java-index,Java Essentials,Java Programming...
# 3
Also, I use netbeans. Is there an easy way to include a png file in my jar? I can see one if so.
nehalema at 2007-7-12 14:57:19 > top of Java-index,Java Essentials,Java Programming...
# 4
I don't know what netbeans is. Here is how to do it from the command line: http://java.sun.com/docs/books/tutorial/deployment/jar/index.html
Hippolytea at 2007-7-12 14:57:19 > top of Java-index,Java Essentials,Java Programming...
# 5

> I have tried this but not in the same way you are

> saying to. Any better examples on doing that? That

> documentation is a bit cryptic to me (a new

> programmer in java).

Here's a Sun tutorial. It rocks:

http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html

This post might help.

http://forum.java.sun.com/thread.jspa?threadID=749816&messageID=4287812

Sorry about the Netbeans thing, I've never used it.

kevjavaa at 2007-7-12 14:57:19 > top of Java-index,Java Essentials,Java Programming...
# 6
Thanks a lot for your help. I'm making some real progress. I have it in my jar from following this forum (which ironically their solution did not work for them but did for me): http://forum.java.sun.com/thread.jspa?threadID=758097&messageID=4330183
nehalema at 2007-7-12 14:57:19 > top of Java-index,Java Essentials,Java Programming...