This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Runnable jar is not including the 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 "Runnable jar is not including the files" Watch "Runnable jar is not including the files" New topic
Author

Runnable jar is not including the files

Vivek Moyal
Ranch Hand

Joined: Nov 02, 2009
Posts: 57
Hello
i use Eclipse Ide for my java work and i was working on a program and have some pictures which is in seperate folder and i have a database file when i run it everything is running and one thing more i am not using DSN for my JDBC connection i m using it directly

when i export it to runnable jar it shows me an error and it doent includes the picture folder and the database file
so please help me out i m in a big trouble because i have to show a demo to a college with presentation and my jar is not working so please help me out as soon as possible
Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161

what if you made the top level folder that contains the images be a "source folder" (even though it doesn' thave any code in it)
right click folder, build path, use as source folder .

For some reason anything that is a source folder, the contents get copied into the eclipse built classes folder, i use that to get .xml files in other non-src folders into the jar.

I have never used the eclipse export to jar file thing, it seems too rigid to a mold of what is a typical project, difficult to do special things like jam images in it.

if making the images folder a sources folder doesn't work, are you able to use ant. ?

something like a "package" target in an ant file, that does a compile, (or we can just take advantage of the eclipse building the .java files. and then do a copy image files into the target folder, and then ant the target folder.

in general, its more elegant to rely on ant to do the packaging of a project anyway (than eclipse project export), as it is more accessible to other people who don't use eclipse. but also, sometimes in a pinch its just faster to type something in a console to rebuild things than to boot up eclipse to quickly rebuild the project.

here is an example


eclipse even supports launching ant files from an integrated panel.

see also:

http://ant.apache.org/manual/index.html


Error: Keyboard not attached. Press F1 to continue.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38033
    
  22
Welcome to JavaRanch Vivek Moyal
Vivek Moyal
Ranch Hand

Joined: Nov 02, 2009
Posts: 57
i dont get what you said here i get something but not the full

bro i dont know abt ANT that how it work and how i have to work over it

will you give an example of simple jar which include picture in it and its code too so i will see the code and apply it to my code
Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161
ok, so after you create your class files

#compile, or let eclipse compile for you.
javac -d bin src/*.java

#remove existing jar file, if any
rm -f myjarfile.jar
# or if you'r windows, delete command i guess


then use the jar command that comes with java, such as in a console in the project folder

# grab the class files
jar cf myjarfile.jar -C bin *

# add to the jar file the stuff in the images folder
jar uf myjarfile.jar -C images *
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Runnable jar is not including the files
 
Similar Threads
where to put my jdbc driver to mysql?
PostgreSql Connection Error:
learning Ant
Java executable jar with embedded Derby DB
Check folder and start program execution further