If you set the paths to the image files, such as:
c:/myfolder/smile.gif
-put the image file here!
Then your jar file should pick them up from wherever you execute it from.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
>By the way, are there any ways to like include the image file into the JAR file and read it from there, so that the end product is just one file. Easier for distribution I guess and it eliminates the need to change the codes everytime.
I don't think that's possible, although I'm just guessing here. The only other way out of it, is to ensure your jar file is in the same directory as your pictures. But like you say that has obvious problems. You can't execute it properly if you drag the jar file elsewhere - the pictures won't link it up.
Hmmm.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
yes, using getResource or better yet getResourceAsStream is the way to extract resources from a jarfile.
Make sure that those resources are contained in the jarfile as part of the classpath or you'll get an error indicating that the resource doesn't exist.
That means that during compilation (and jarring) the files need to be copied so they exist next to the classfiles for the application.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
Right click on the project >> select PROPERTIES. In the pop-up window, in CATEGORIES (left side listing) select Libraries & Resources >>on the right press Add JAR/Folder and navigate to place where is the driver or any other library you wish to add >> highlight file/s you want to include and press OK.
You can see sample here
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902