• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

including files in .jar file using eclipse IDE

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow its a while since i've posted, reel life caught up with me so i had to put my programing learning on the back burnner, but now im back

Anyway here's my problem, I have a project that i decided to have a Jpanel with logo in it do i used the following code,

This is just the method i used to create the JPanel and this works fine. My problem is when i compile my code into a exectuable Jar and run it the logo doesn't appear. so to find out why i added this code to bugtest

when run in the IDE the image appears fine, but when i compile and then run the image doesn't appear and it gives me the JLabel meaning that the file dosen't exsist!

I think my question is is there a particular way of telling eclipse to incude the extra file when it compiles to a .jar file.

thanks in advance,

sam
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Woodhams wrote:
I think my question is is there a particular way of telling eclipse to incude the extra file when it compiles to a .jar file.



It's pretty straightforward. Just add the image file to the list when you are using the eclipse jar packager to create the jar file.


However, that is not the problem. Even with the image file in the jar file, hence, the class path, the File class doesn't support files located in a jar file. The File class is for files in the file system.

If your program needs the image file as a file, then your program will need to copy the image in the jar file, to the file systems, first.

Henry
 
Sam Woodhams
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok that makes more sence, thanks.

Is there anyway to load the image into the jar and then accses it in the jar?
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmm looks like i have 2 accounts...oops, did wonder why the post count was so low :P

Anyway i've had a look round to see if i could solve my problem on my own and i've come up with the follwing code.

I know this doesn't due to the fact that i never "run" the inner class, mainly because im not sure how. any attempt to do logo.add() or variations doesn't work. so how do i refference the inner class in a way that will make it draw the picture? and if i do will the above code actually work?

Thanks in advance

sam
 
Samuel Woodhams
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no problems guys i got it fixed on my own love that when it happens, anyway here is the changed codeincase anyone else comes up agianst a similier problem,

its very similar to the origanal code insted it uses the .getResource() method do it can retrive the file from the jar.
reply
    Bookmark Topic Watch Topic
  • New Topic