aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes including files in .jar file using eclipse IDE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "including files in .jar file using eclipse IDE" Watch "including files in .jar file using eclipse IDE" New topic
Author

including files in .jar file using eclipse IDE

Sam Woodhams
Greenhorn

Joined: Sep 01, 2009
Posts: 3
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
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18829
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Sam Woodhams
Greenhorn

Joined: Sep 01, 2009
Posts: 3
ok that makes more sence, thanks.

Is there anyway to load the image into the jar and then accses it in the jar?
Samuel Woodhams
Ranch Hand

Joined: Sep 01, 2009
Posts: 31
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

Joined: Sep 01, 2009
Posts: 31
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: including files in .jar file using eclipse IDE