开发者

creating jar file

开发者 https://www.devze.com 2022-12-08 09:45 出处:网络
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 structurefrom following url

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 whe开发者_如何学编程n jar is creating. it has no other folders and images to select.


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.


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.


Building a jar using jar tool: http://java.sun.com/docs/books/tutorial/deployment/jar/build.html

Building a jar using ant: http://www.developer.com/tech/article.php/989631/Building-with-Ant-Introduction.htm

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号