Download presentation
Presentation is loading. Please wait.
Published byElizabeth Warren Modified over 9 years ago
1
Objectives:1. Archiving and Packaging Java Code 2. The jar Program 3. Example Applet JAR Files
2
JAR file archives provide packaging for applications, applets, & JavaBeans Multiple classes can be packaged in JAR files JAR Files specified within HTML Manifest file JAR files use ZIP compression format
3
JAR Files: provide a delivery mechanism for JavaBeans, packaging all the necessary resources together in a single file. Multiple Beans may be contained in a single JAR file, and the file may also contain an optional manifest which lists the contents. help transport Beans over the Internet in easy-to- manage packages, and they are also used to archive applets for more efficient downloading performance.
4
The jar Utility Creates JAR files Adds to existing archives Extracts items in an archive Lists archive contents Syntax: jar {ctux} [vfm0M] [jar-file] [manifest-file] files
5
jar Command jar {ctux} [vfm0M] [jar-file] [manifest-file] files jar-file specifies the name of the archive file. No required naming conventions exist for Java archive files, although you will most likely see the file extension.jar associated with them. The manifest-file argument is a file containing a list of the jar file contents. A manifest file is required when using the m command line option. More...
6
jar Command jar {ctux} [vfm0M] [jar-file] [manifest-file] files files to be archived are listed at the end of the command and are separated by whitespace. Wildcard characters are accepted directory names are followed recursively, i.e., all files in subdirectories will also be archived. File names are relative to the directory from which you run the jar command special –C option introduced in Java 1.2 to change the relative directory. forward or backward slashes are accepted, making the jar command operating-system independent.
7
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
8
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
9
JAR Files & HTML Improve Applet download performance compression of JAR files allows efficient downloading of applets over the Web. entire archive may be downloaded in a single HTTP transaction. avoids reconnect each time a specific.class file or resource is needed. ARCHIVE Tag filename is relative to the location of the HTML page. still need a CODE tag to indicate which class within the archive starts the applet.
10
The Manifest The manifest file exists to provide information about the contents of its associated jar file. Automatically created if not specified otherwise, named manifest.mf placed in the archive under a directory called /META-INF M option in jar command suppresses creation. Lists the entries in the archive First entry identifies manifest version Example: Manifest-Version: 1.0 Created-By: 1.5.0 (Sun Microsystems Inc.) applies to the entire JAR file
11
Manifest Contents Subsequent sections must begin with Name: describe individual elements JavaBeans, files, packages, and URLs. Each section of the manifest file refers to an entry in the archive and is separated by a blank line. Attribute-value pairs of the format attribute: value are used in each section to give information about that particular entry. Name: Calculator.class lines describing this file Name: edu/weber/mypkg lines describing this package
12
Manifest Contents Attribute/Value pairs Note Java-Bean attribute in example: Name: StockBroker/Simulator/Stock.class Digest-Algorithms: MD5 SHA MD5-Digest: wuXrtYN-56Nn4rtDFewq=-tr SHA-Digest: fg67tKdkfR65-SRkdrslegvY-tyK Java-Bean: True
13
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
14
Creating the Archive File create an archive file with a customized manifest file by using both the m and f options and giving the required arguments as shown in the slide. The generated manifest.mf file in the archive should have the information given in Simulator.mf (which you write). > jar cfm Simulator.jar Simulator.mf StockBroker/Simulator/Stock.class StockBroker/Simulator/Helper.class StockBroker/Simulator/Price.class if the jar options contain both the letters f and m, the JAR and manifest files listed in the command line should be in the same order. For example, if f comes before m, the JAR filename should come before the manifest filename.
15
Examples See Composites using a jar at: http://acad.kutztown.edu/~spiegel/cis421/Composite/JAR/ jar contains three classes ButtonPanel.class RadioPanel.class Test1.class(code; this class is used to start applet) See Animation Demo using a jar at: http://acad.kutztown.edu/~spiegel/cis421/Animation/AppletJAR/ball.htm inner classes specified in a manifest
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.