[Contents] [Previous] [Next] [Index]

## Chapter 7
Packaging Components for Import

This document describes how to use the Java Developer Kit (JDK) 1.1 JAR packager to package multiple components and their support files prior to importing them into Visual JavaScript (VJS). Only some components require packaging before import. This document identifies the conditions under which you must use the JAR packager.

Sections in this document include the following topics:

- When is the JAR Packager Required?
- Packaging a Component

## When is the JAR Packager Required?

You do not always have to package components into JAR files before importing the components into VJS. There are only two situations that require packaging prior to importing. When a:

- JavaScript components that are defined in multiple files, such as those that use supporting JavaScript functions or Java classes located in other files.

- Java object makes use of separate supporting files (which is most of the time).

In all other situations, packaging is optional.

## Packaging a Component

To package a component in a JAR file, you need the Java Developer's Kit (JDK) version 1.1. At least one of the files you put into a JAR file must be a JavaBean as defined in the JDK 1.0.2 transitional bean specification (a JavaScript component in a JSB file qualifies as a Java Bean for this purpose).

To create the JAR file using the JAR packager in the JDK, follow these steps:

1. Create a temporary working directory. Copy the beans and any related .CLASS files to the working directory.

2. Create subdirectories for your CLASS files, if necessary. If the classes are in packages, you must make subdirectories. Make the subdirectories relative to the working directory, and move the beans into them. For example, if a Java Bean "Molecule.class" is in the package "sunw.demo.molecule", you should move Molecule.class to the subdirectory sunw/demo/molecule under your working directory.

3. In the working directory, create a manifest file. This is an ASCII file listing all the files to be included in the archive. If all the .CLASS and .JSB files you want to include in the JAR file are already beans, this both this step and the next are optional. If you have one manifest for a directory, name the file "MANIFEST.MF" (all uppercase). If you have more than one, you can give them different names, and internally, they will be combined into a single manifest file named MANIFEST.MF. The first line in this file should contain this:

          Manifest-Version: 1.0

4. Create one entry in the manifest file for each JavaScript component in the archive. Each entry must have two lines. The first line gives the name of the class and the second indicates if the class is a Java Bean. Case is significant in these names. For example, here is the entry for the Molecule applet bean:

          Name: sunw/demo/molecule/Molecule.class

          Java-Bean: True

5. Make sure the JDK1.1 bin directory is in your PATH so you can execute the "jar" command.

6. To create a JAR file, use the command:

          jar cfm jar-name manifest-name bean-name1 bean-name2...

   For example to create a JAR file called Avogadro.jar to hold the Molecule class, use the following command:

          jar cfm Avogadro.jar MANIFEST.MF sunw/demo/molecule/Molecule.class

   If you did not need to create a manifest file in step 3, then the command to create a JAR file takes the form:

          jar cfm jar-name bean-name..

   Be sure to list each file to include if you use this second form of the JAR command.

If this command executes successfully, you should now have a JAR file containing your components. You can use the JAR file to import the components into a VJS palette for testing and use.

To examine the contents of a JAR file, you can execute the following command:

       jar tf jar-name

[Contents] [Previous] [Next] [Index]

Last Updated: 09/03/97 11:33:53

Copyright © 1997 Netscape Communications Corporation