110 likes | 249 Views
Objectives: 1. Archiving and Packaging Java Code 2. The jar Program. JAR Files. 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.
E N D
Objectives: 1. Archiving and Packaging Java Code 2. The jar Program JAR Files
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 JAR Files
Creates JAR files Extracts Contained Elements Lists JAR file contents Usage: jar {ctux} [vfm0M] [jar-file] [manifest-file] files The jar Program
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 jar command line options
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 Examples of jar command
Improve Applet download performance ARCHIVE Tag <APPLET ARCHIVE=“Simulator.jar” CODE=Stock.class WIDTH=350 HEIGHT=250> </APPLET> JAR Files & HTML
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.5.0 (Sun Microsystems Inc.) The Manifest
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 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 Manifest Contents
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 Custom Manifest File Indicating Beans
jar cfm Simulator.jar Simulator.mf StockBroker/Simulator/Stock.class StockBroker/Simulator/Helper.class StockBroker/Simulator/Price.class Creating the Archive File