• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Runnable jar is not including the files

 
Vivek Moyal
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 161
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Campbell Ritchie
Sheriff
Pie
Posts: 47222
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch Vivek Moyal
 
Vivek Moyal
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 161
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 *
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic