Presentation is loading. Please wait.

Presentation is loading. Please wait.

Objectives:1. Archiving and Packaging Java Code 2. The jar Program JAR Files.

Similar presentations


Presentation on theme: "Objectives:1. Archiving and Packaging Java Code 2. The jar Program JAR Files."— Presentation transcript:

1 Objectives:1. Archiving and Packaging Java Code 2. The jar Program JAR Files

2  JAR file archives provide packaging for Application, Applets, & JavaBeans  Multiple classes can be packaged in JAR files  JAR Files with HTML  Manifest file  JAR files use ZIP compression format

3 The jar Program  Creates JAR files  Extracts Contained Elements  Lists JAR file contents  Usage: jar {ctux} [vfm0M] [jar-file] [manifest-file] files

4 jar command line options  Only one of the following c: Create a new archive file t: List the table of contents for the archive file u: Update the contents of the archive or manifest x: Extract named files (or all) from the archive  Other options can be combined or omitted v: Verbose output f: Specify [jar-file] m: Include information from [manifest-file] 0: Do not use compression M: Do not create a manifest file for the archive entries

5 Examples of jar command  Create an archive called Simulator.jar that contained the single class Machine.class jar cf Simulator.jar Machine.class  List the table of contents of Simulator.jar using verbose output jar tvf Simulator.jar  Extract all contents of Simulator.jar jar xvf Simulator.jar

6 JAR Files & HTML  Improve Applet download performance  ARCHIVE Tag

7 The Manifest  Automatically created  Named /META-INF/Manifest.mf  Lists the entries in the archive  First entry identifies manifest version Manifest-Version: 1.0 Created-By: 1.4.2_02 (Sun Microsystems Inc.)

8 Manifest Contents  Main section shown in previous slide  Applies to the entire JAR file  Subsequent sections must begin with Name: entry and describe individual elements contained in JAR file like JavaBeans, files, packages, and URLs. Name: Calculator.class lines describing this file Name: edu/weber/mypkg lines describing this package

9 Manifest Contents  Attribute/Value pairs  Note Java-Bean attribute Name: StockBroker/Simulator/Stock.class Digest-Algorithms: MD5 SHA MD5-Digest: wuXrtYN-56Nn4rtDFewq=-tr SHA-Digest: fg67tKdkfR65-SRkdrslegvY-tyK Java-Bean: True

10 Custom Manifest File Indicating Beans Manifest-Version: 1.0 Name: StockBroker/Simulator/Stock.class Java-Bean: True Name: StockBroker/Simulator/Helper.class Java-Bean: False Name: StockBroker/Simulator/Price.class Java-Bean: True

11 Creating the Archive File jar cfm Simulator.jar Simulator.mf StockBroker/Simulator/Stock.class StockBroker/Simulator/Helper.class StockBroker/Simulator/Price.class


Download ppt "Objectives:1. Archiving and Packaging Java Code 2. The jar Program JAR Files."

Similar presentations


Ads by Google