1 / 19

Jar Files

Jar Files. The Basics. Outline. Create a Jar Viewing the Contents of a JAR File Extracting the Contents of a JAR File Modifying a Manifest File Running JAR-Packaged Software. Create a Jar. The basic format of the jar command: jar cf jar-file input-file(s)

zariel
Download Presentation

Jar Files

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Jar Files The Basics

  2. Outline • Create a Jar • Viewing the Contents of a JAR File • Extracting the Contents of a JAR File • Modifying a Manifest File • Running JAR-Packaged Software

  3. Create a Jar The basic format of the jar command: jar cf jar-file input-file(s) • The c option says: create a JAR. • The f option says: create it as a file. • jar-file: the file’s name. By convention, JAR filenames have a .jar extension. • input-file(s): a space-separated file list to be archived. • An input-file can contain the wildcard * symbol. • A directory’s contents are added recursively.

  4. The generated JAR resides, compressed, in the current directory. • It also generates a default manifest file. • Some other options: • v: Writes each added file’s name to stdout. • 0: (zero) Don’t compress the JAR file.

  5. Example • The TicTacToe applet demo comprises: • a class file • audio directory: contain sound files • images directory: contain GIF images all in a directory called TicTacToe:

  6. In the TicTacToe directory, execute jar cvf TicTacToe.jar TicTacToe.class audio images • TicTacToe.jar is placed in the current directory. • The verbose output appears on the next slide.

  7. adding: TicTacToe.class (in=3825) (out=2222) (deflated 41%) adding: audio/ (in=0) (out=0) (stored 0%) adding: audio/beep.au (in=4032) (out=3572) (deflated 11%) adding: audio/ding.au (in=2566) (out=2055) (deflated 19%) adding: audio/return.au (in=6558) (out=4401) (deflated 32%) adding: audio/yahoo1.au (in=7834) (out=6985) (deflated 10%) adding: audio/yahoo2.au (in=7463) (out=4607) (deflated 38%) adding: images/ (in=0) (out=0) (stored 0%) adding: images/cross.gif (in=157) (out=160) (deflated -1%) adding: images/not.gif (in=158) (out=161) (deflated -1%)

  8. Using the Wildcard Character Using the wildcard character (*), an equivalent command, in this case, is: jar cvf TicTacToe.jar *

  9. Outline • Create a Jar • Viewing the Contents of a JAR File • Extracting the Contents of a JAR File • Modifying a Manifest File • Running JAR-Packaged Software

  10. Viewing the Contents of a JAR File • To view a jar, execute: jar tf jar-file The t option: view the JAR’s table of contents. • Example (continued) jar tf TicTacToe.jar This command’s output appears on the next slide.

  11. META-INF/MANIFEST.MF TicTacToe.class audio/ audio/beep.au audio/ding.au audio/return.au audio/yahoo1.au audio/yahoo2.au images/ images/cross.gif images/not.gif

  12. jar tvf TicTacToe.jar displays 256 Mon Apr 20 10:50:28 PDT 1998 META-INF/MANIFEST.MF 3885 Mon Apr 20 10:49:50 PDT 1998 TicTacToe.class 0 Wed Apr 15 16:39:32 PDT 1998 audio/ 4032 Wed Apr 15 16:39:32 PDT 1998 audio/beep.au 2566 Wed Apr 15 16:39:32 PDT 1998 audio/ding.au 6558 Wed Apr 15 16:39:32 PDT 1998 audio/return.au 7834 Wed Apr 15 16:39:32 PDT 1998 audio/yahoo1.au 7463 Wed Apr 15 16:39:32 PDT 1998 audio/yahoo2.au 0 Wed Apr 15 16:39:44 PDT 1998 images/ 157 Wed Apr 15 16:39:44 PDT 1998 images/cross.gif 158 Wed Apr 15 16:39:44 PDT 1998 images/not.gif

  13. Outline • Create a Jar • Viewing the Contents of a JAR File • Extracting the Contents of a JAR File • Modifying a Manifest File • Running JAR-Packaged Software

  14. Extracting a JAR’s Contents • To extract the contents of a JAR, execute: jar xf jar-file The x option: extract files from jar-file. • This overwrites existing files having the same pathname as the extracted files. • Example (continued) jar xf TicTacToe.jar Extracts the JAR’s files into the current directory.

  15. Outline • Create a Jar • Viewing the Contents of a JAR File • Extracting the Contents of a JAR File • Modifying a Manifest File • Running JAR-Packaged Software

  16. Modifying a Manifest File • To create a JAR & add manifest info: jar cmf manifest-addition jar-file input-file(s) The m option: merge a manifest file into the JAR’s. manifest-addition: the manifest file’s name. • To designate the main class in the JAR, the manifest-addition file contains the line: Main-Class: classname where classname must omit the .class extension E.g., TicTacToe (not TicTacToe.class)

  17. Outline • Create a Jar • Viewing the Contents of a JAR File • Extracting the Contents of a JAR File • Modifying a Manifest File • Running JAR-Packaged Software

  18. Running JAR-Packaged Software Applets Packaged in JAR Files <applet code=TicTacToe.class archive="TicTacToe.jar" width=120 height=120> </applet> • The archive parameter specifies the relative path to the JAR file. • This example assumes that the JAR & HTML files are in the same directory.

  19. JAR Files as Applications - 1.2 platform java -jar jar-file The JAR’s manifest must designate the main-class. • Example (continued) java -jar TicTacToe.jar Based on the TicTacToe.jar with the manifest that designates TicTacToe as the main-class.

More Related