JAR Files Objectives 1 Archiving and Packaging Java
JAR Files Objectives: 1. Archiving and Packaging Java Code 2. The jar Program
JAR Files 1 JAR file archives provide packaging for Application, Applets, & Java. Beans 1 Multiple classes can be packaged in JAR files 1 JAR Files with HTML 1 Manifest file 1 JAR files use ZIP compression format
The jar Program 1 Creates JAR files 1 Extracts Contained Elements 1 Lists JAR file contents 1 Usage: jar {ctux} [vfm 0 M] [jar-file] [manifest-file] files
jar command line options 1 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 1 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
Examples of jar command 1 Create an archive called Simulator. jar that contained the single class Machine. class jar cf Simulator. jar Machine. class 1 List the table of contents of Simulator. jar using verbose output jar tvf Simulator. jar 1 Extract all contents of Simulator. jar xvf Simulator. jar
JAR Files & HTML 1 Improve Applet download performance 1 ARCHIVE Tag <APPLET ARCHIVE=“Simulator. jar” CODE=Stock. class WIDTH=350 HEIGHT=250> </APPLET>
The Manifest 1 Automatically created 1 Named /META-INF/Manifest. mf 1 Lists the entries in the archive 1 First entry identifies manifest version Manifest-Version: 1. 0 Created-By: 1. 5. 0 (Sun Microsystems Inc. )
Manifest Contents 1 Main section shown in previous slide FApplies to the entire JAR file 1 Subsequent sections must begin with Name: entry and describe individual elements contained in JAR file like Java. Beans, files, packages, and URLs. Name: Calculator. class lines describing this file Name: edu/weber/mypkg lines describing this package
Manifest Contents 1 Attribute/Value pairs 1 Note Java-Bean attribute Name: Stock. Broker/Simulator/Stock. class Digest-Algorithms: MD 5 SHA MD 5 -Digest: wu. Xrt. YN-56 Nn 4 rt. DFewq=-tr SHA-Digest: fg 67 t. Kdkf. R 65 -SRkdrslegv. Y-ty. K Java-Bean: True
Custom Manifest File Indicating Beans Manifest-Version: 1. 0 Name: Stock. Broker/Simulator/Stock. class Java-Bean: True Name: Stock. Broker/Simulator/Helper. class Java-Bean: False Name: Stock. Broker/Simulator/Price. class Java-Bean: True
Creating the Archive File jar cfm Simulator. jar Simulator. mf Stock. Broker/Simulator/Stock. class Stock. Broker/Simulator/Helper. class Stock. Broker/Simulator/Price. class
- Slides: 11