Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

including files in .jar file using eclipse IDE

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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: 23853
141
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.
 
What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!