Jar Files - PowerPoint PPT Presentation

About This Presentation
Title:

Jar Files

Description:

Jar Files The Basics – PowerPoint PPT presentation

Number of Views:617
Avg rating:3.0/5.0
Slides: 20
Provided by: PeterC208
Category:
Tags: files | jar | java | spring

less

Transcript and Presenter's Notes

Title: Jar Files


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 files 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 directorys 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 files name to stdout.
  • 0 (zero) Dont 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 (in3825) (out2222)
    (deflated 41)
  • adding audio/ (in0) (out0) (stored 0)
  • adding audio/beep.au (in4032) (out3572)
    (deflated 11)
  • adding audio/ding.au (in2566) (out2055)
    (deflated 19)
  • adding audio/return.au (in6558) (out4401)
    (deflated 32)
  • adding audio/yahoo1.au (in7834) (out6985)
    (deflated 10)
  • adding audio/yahoo2.au (in7463) (out4607)
    (deflated 38)
  • adding images/ (in0) (out0) (stored 0)
  • adding images/cross.gif (in157) (out160)
    (deflated -1)
  • adding images/not.gif (in158) (out161)
    (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 JARs table of contents.
  • Example (continued)
  • jar tf TicTacToe.jar
  • This commands 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 105028 PDT 1998
    META-INF/MANIFEST.MF
  • 3885 Mon Apr 20 104950 PDT 1998 TicTacToe.class
  • 0 Wed Apr 15 163932 PDT 1998 audio/
  • 4032 Wed Apr 15 163932 PDT 1998 audio/beep.au
  • 2566 Wed Apr 15 163932 PDT 1998 audio/ding.au
  • 6558 Wed Apr 15 163932 PDT 1998 audio/return.au
  • 7834 Wed Apr 15 163932 PDT 1998 audio/yahoo1.au
  • 7463 Wed Apr 15 163932 PDT 1998 audio/yahoo2.au
  • 0 Wed Apr 15 163944 PDT 1998 images/
  • 157 Wed Apr 15 163944 PDT 1998
    images/cross.gif
  • 158 Wed Apr 15 163944 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 JARs 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 JARs 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
    JARs.
  • manifest-addition the manifest files 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
  • ltapplet codeTicTacToe.class archive"TicTacToe.ja
    r"
  • width120 height120gt
  • lt/appletgt
  • 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 JARs 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.
Write a Comment
User Comments (0)
About PowerShow.com