Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can not display Icons when running an executable jar files.

 
Sammy Bill
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11185
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sammy Bill
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11185
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sammy Bill
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic