*
The moose likes Swing / AWT / SWT and the fly likes Can not display Icons when running an executable jar files. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Can not display Icons when running an executable jar files." Watch "Can not display Icons when running an executable jar files." New topic
Author

Can not display Icons when running an executable jar files.

Sammy Bill
Ranch Hand

Joined: Dec 29, 2008
Posts: 96
Hello,

I finished developing an swing application and packed it in a jar file.
when i execute the jar file. the Icons are not displayed.

I tried :
Thread.currentThread().getContextClassLoader().getResource("image.jpg");
and it worked on some of the icons.

I also tried:

this.getClass().getResource("image.jpg");
but nothing.

Is there another way to use images when running the application from a jar file.

Thanks in advance
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10175
    
    8

Oussama M Billah wrote:..
and it worked on some of the icons.


Please ensure the file extensions of your image files inside the jar have not changed. e.g.logo.JPG instead of logo.jpg


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Sammy Bill
Ranch Hand

Joined: Dec 29, 2008
Posts: 96
Maneesh Godbole wrote:

Please ensure the file extensions of your image files inside the jar have not changed. e.g.logo.JPG instead of logo.jpg


Thanks. I just checked them and they are the same as the original ones, so It is not the problem.
Also, When i run the project from eclipse, the following code

Thread.currentThread().getContextClassLoader().getResource("images.jpg");

returns null ( even though i m sure the image exists in the specified path.

one more thing how can i see the exception thrown when running the application from the executable jar file?

Thanks

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10175
    
    8

If you execute the jar with java -jar MyJar.jar (dont forget the .jar extenstion!), it will popup a console where you can see the stack trace.

Why are you using Thread.getCurrentThread....? You can also call getClass().getResource(). Please try it out.

If it still doesn't work, please let us know where your images are in the package.
Sammy Bill
Ranch Hand

Joined: Dec 29, 2008
Posts: 96
Maneesh Godbole wrote:

Why are you using Thread.getCurrentThread....? You can also call getClass().getResource(). Please try it out.

If it still doesn't work, please let us know where your images are in the package.


I tried Thread.getCurentThread.... and getClass()...... and none of them work.
I m storing the images in /images folder.

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Oussama M Billah wrote:I m storing the images in /images folder.

So your images are not located in the same folder as the class files? Then you need to modify your resource string: "/images/image.jpg".

I suggest you reread the API documentation on Class.getResource and ClassLoader.getResource.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sammy Bill
Ranch Hand

Joined: Dec 29, 2008
Posts: 96
Rob Prime wrote:
Oussama M Billah wrote:I m storing the images in /images folder.

So your images are not located in the same folder as the class files? Then you need to modify your resource string: "/images/image.jpg".

I suggest you reread the API documentation on Class.getResource and ClassLoader.getResource.


Sorry, The code fragment i presented was just a sample, it my code i m specifying the "/images/image1.jpg". but still nothing.

any other ideas?

Thanks
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Oussama M Billah wrote:any other ideas?

Yes, rather than have us guess what your actual code looks like and what's wrong, create a small app that demonstrates the error, is compilable and runnable, and has no extraneous code not relevant to the problem, and post it here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can not display Icons when running an executable jar files.
 
Similar Threads
How to specify a path of a certain file?
custom DefaultListCellRenderer only works on one PC
Load file inside JAR??
problems with runme.jar referencing resources
Problem getting image from JAR file