1 / 15

Objectives: 1. Archiving and Packaging Java Code 2. The jar Program 3. Example Applet

Objectives: 1. Archiving and Packaging Java Code 2. The jar Program 3. Example Applet. JAR Files. JAR file archives provide packaging for applications, applets, & JavaBeans Multiple classes can be packaged in JAR files JAR Files specified within HTML Manifest file

Download Presentation

Objectives: 1. Archiving and Packaging Java Code 2. The jar Program 3. Example Applet

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 JAR Files

  3. 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. JAR Files:

  4. Creates JAR files Adds to existing archives Extracts items in an archive Lists archive contents Syntax: jar {ctux} [vfm0M] [jar-file] [manifest-file] files The jar Utility

  5. 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... jar Commandjar {ctux} [vfm0M] [jar-file] [manifest-file] files

  6. 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. jar Commandjar {ctux} [vfm0M] [jar-file] [manifest-file] files

  7. 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

  8. 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

  9. 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 <APPLET ARCHIVE=“Simulator.jar” CODE=Stock.class WIDTH=350 HEIGHT=250> </APPLET> 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. JAR Files & HTML

  10. 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 The Manifest

  11. Subsequent sections must begin with Name: <entry> 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 Manifest Contents

  12. 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 Manifest Contents

  13. 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

  14. create an archive file with a customized manifest file by using both the m and foptions 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. Creating the Archive File

  15. See Composites using a jar in the Mastermind Directory See Animation Demo using a jar at: http://acad.kutztown.edu/~spiegel/cis421/Animation/AppletJAR/ball.htm inner classes specified in a manifest Examples

More Related