accessing images in a jar (already read other threads but not resolved )

Hi everyone,

I know this topic has already been answered and I have read most of them and tried to all the solutions but still I can not get my images in the jar...

for uploading icons and images in to my java application I use the following method:

private static ImageIcon createIconImage(String imageFile) {

ImageIcon image = null;

String extention = ".gif";

String imageLocation = "../" + imageFile + extention;

URL imageURL = MyClass.class.getResource(imageLocation);

System.out.println(imageURL);

if (imageURL == null)

System.err.println("The file: " + imageLocation + " does not exist !");

else

image = new ImageIcon(imageURL);

return image;

}

My directories are situated as bellow:

[javadev]

|

+-[mypackage]

||

|+[AllClassFolders]

|||

||+[folder1]

|||

||+[folder2]

||

|+[icons]

|||

||.- icon1.gif

||.- icon2.gif

||

|+[img]

|||

||.- img1.gif

||.- img2.gif

|

+ -[test]

+ -[anotherdirectory]

But what ever i do i can not have access to these images. In my manifest file I have:

Main-Class: myMainClass

Class-Path: swing-layout-1.0.jar (which is a jar file with some of swing layouts)

Does anyone has any idea how I can solve this problem? I have almost spent 5 hourse to solve this problem with different proposed solutions in this forum but no result.. I am almost depressed ;)

So I would be greatful if I someone can help me.

Take care

[1609 byte] By [pishi13a] at [2007-10-3 8:47:17]
# 1
Nobody has any idea?
pishi13a at 2007-7-15 3:56:15 > top of Java-index,Desktop,Deploying...
# 2
What does the System.err.println show for the URL? When you jar the file, is the director structure jar_root/img/img1.gif for example/ I think you should not have ../ in the path. It likely should start with /img/
atmguya at 2007-7-15 3:56:16 > top of Java-index,Desktop,Deploying...
# 3
When you jar the file, is the directory structure jar_root/img/img1.gif for example? I think you should not have ../ in the path. It likely should start with /img/
atmguya at 2007-7-15 3:56:16 > top of Java-index,Desktop,Deploying...
# 4
Thanx for the reply.. I will try with this one and will let u know the result :) Hope that solve my problem.Have a nice day.
pishi13a at 2007-7-15 3:56:16 > top of Java-index,Desktop,Deploying...
# 5

You know what!! You are an angle :)

Actually since my icons and images where not in the same folder as my class I needed to add ../ to have access to them.

Now I have placed them in the same folder and I changed the ../img/fileName.gif to img/fileName.gif and it works perfectly. You have saved my life lol :)

Take care

pishi13a at 2007-7-15 3:56:16 > top of Java-index,Desktop,Deploying...