tags:

views:

312

answers:

3

can some one explain me how to crate jar file. my source folder has various sub folders and image files. you can see images explaining source folder structure from following url http://img63.imageshack.us/gal.php?g=capturev.png. when jar is created using eclipse export jar function, it only include class files only , but i want to create jar file for all the content in my source folder. third image shows the window i get when jar is creating. it has no other folders and images to select.

+1  A: 

You can do this from the command line using the jar command:

Usage: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
Options:
    -c  create new archive
    -t  list table of contents for archive
    -x  extract named (or all) files from archive
    -u  update existing archive
    -v  generate verbose output on standard output
    -f  specify archive file name
    -m  include manifest information from specified manifest file
    -e  specify application entry point for stand-alone application 
        bundled into an executable jar file
    -0  store only; use no ZIP compression
    -M  do not create a manifest file for the entries
    -i  generate index information for the specified jar files
    -C  change to the specified directory and include the following file
If any file is a directory then it is processed recursively.
The manifest file name, the archive file name and the entry point name are
specified in the same order as the 'm', 'f' and 'e' flags.

Example 1: to archive two class files into an archive called classes.jar: 
       jar cvf classes.jar Foo.class Bar.class 
Example 2: use an existing manifest file 'mymanifest' and archive all the
           files in the foo/ directory into 'classes.jar': 
       jar cvfm classes.jar mymanifest -C foo/ .

But personally, I'd use something like Ant or Maven for this purpose.

Pascal Thivent
+3  A: 

See the Sun jar tutorial.

Whilst you can run jar from the command line, I'd recommend using Ant and the Ant Jar task. It will give you a lot more control over how to build the jar file and what to include in it.

e.g.

  <jar destfile="${dist}/lib/app.jar"
       basedir="${build}/classes"
       excludes="**/Test.class"
  />

will build everything in the classes directory into a .jar file, but exclude the Test classes.

Brian Agnew