JPack, Version 1.0

(C) Copyright 2000, Adam Doppelt, All rights reserved.
amd@gurge.com



JPack v1.0 was released on February 13, 1997.

This document is divided into the following sections:

  1. What is JPack?
  2. Usage
  3. ZIP.EXE and CABARC.EXE
  4. Examples
  5. FAQ


1. What is JPack?

Netscape Navigator 3.0 and Internet Explorer 3.0 both allow the Java developer to pack a bunch of classes together into a single archive, vastly improving download speed and decreasing strain on the web server. Unfortunately, the two browses use different (but non- interfering) mechanisms for packing the classes together. Navigator looks for an uncompressed ZIP file using the ARCHIVE parameter, and Internet Explorer looks for a CAB file using the CABBASE parameter.

JPack is a little DOS application I whipped up to automate the process of building these archive files, and to help create the APPLET tags to support them. Just give JPack a list of packages, and it will do the rest.

The JPack home page is currently located at:

2. Usage

JPACK archive_name package(s)
"archive_name" will be used as the base name for creating the two archives. For example, passing "Animator" results in two files being created, animator.cab and animator.zip.

The package names are used by JPack to find the classes, and also to define the necessary structure inside the archives. Use "." to archive the class files in the current directory if you aren't using a package.

When you run JPack, it will create ZIP and CAB files containing the given classes. JPack will also output a template APPLET tag for loading an applet using these archives.

3. ZIP.EXE and CABARC.EXE

JPack doesn't actually create the archives itself. Instead, it requires two freely available applications, ZIP.EXE and CABARC.EXE to create the archives. You must already have these applications before you can use JPack. If JPack cannot find both of these applications somewhere in your PATH, it will not work.

ZIP.EXE is a version of zip which supports long file names and can be used from the command line. Pkzip 2.04g doesn't cut it, since it doesn't support long file names. ZIP.EXE is distributed as part of the InfoZip library. JPack has been tested with ZIP version 2.0.1. The latest version of the InfoZip library can be found at:

CABARC.EXE is a Microsoft tool which helps automate the process of creating CAB files. JPack has been tested with CABARC version 1.0. The latest version can be found in the CAB developer's kit:

If those URLs are no longer valid, look for updated links at the JPack home page:

4. Examples

TinyMouse

Let's say you've just finished an Applet called TinyMouse, consisting of eight classes, none of which are in packages. Your directory might be organized like this:

   c:\classes\
     TinyMouse.class    TinyApplet.class    TinyCat.class
     TinyHamster.class  ...
You've just downloaded JPack (as well as ZIP.EXE and CABARC.EXE) to package all eight classes into a single archive, improving download speed immensely. Assuming JPACK.EXE, ZIP.EXE and CABARC.EXE are all in your path somewhere, you can create the archives by typing:
   c:\>cd c:\classes\
   c:\classes\>jpack mouse .
The "." tells JPack to archive just the classes in the current directory. JPack will create two archives (mouse.cab and mouse.zip) and spit out the following APPLET template:

<APPLET CODE="[???].class" WIDTH=[???] HEIGHT=[???] CODEBASE="[dir containing ZIP/CAB files and Java classes]" ARCHIVE="mouse.zip"> <PARAM NAME="CABBASE" VALUE="mouse.cab"> </APPLET> On your web server, you could organize the applet as follows:

   java/tinymouse/        (TinyMouse directory)
     index.html              (TinyMouse home page)
     classes/               (directory containing classes and archives)
       mouse.cab              (used by Internet Explorer)
       mouse.zip              (used by Netscape)
       TinyMouse.class        (used by all other browsers)
       TinyApplet.class       ...
       ...
In order to load this applet, you would have to copy the APPLET template that JPack produced into tinymouse/index.html, and modify it to read:

<APPLET CODE="TinyMouse.class" WIDTH=100 HEIGHT=100 CODEBASE="classes" ARCHIVE="mouse.zip"> <PARAM NAME="CABBASE" VALUE="mouse.cab"> </APPLET> Sneakers

Your latest applet, Sneakers, is a masterpiece. Based on an old Apple II game, it features double buffering, smooth scrolling, and lots of heart pounding animated fun. The only problem is that the applet turned out to be a real behemoth - thirty classes in three different packages. Naturally, you want to pack all of these classes into an archive to speed things up.

The Sneakers applet is organized into three packages (sneakers.game, sneakers.sound, and highscore), and looks something like this:

   c:\classes\
     sneakers\
       game\
         Applet.class   Meteor.class      Player.class    ...
       sound\
         Bang.class     Bop.class         GameOver.class  ...
     highscore\
       NewHigh.class  ShowScores.class  Client.class      ...
Having just installed JPack, ZIP.EXE, and CABARC.EXE you pack up the files by typing:

   c:\>cd c:\classes\
   c:\classes\>jpack sneakers sneakers.game sneakers.sound highscore
JPack will create two archives (sneakers.cab and sneakers.zip) and spit out the following APPLET template:

<APPLET CODE="[???].class" WIDTH=[???] HEIGHT=[???] CODEBASE="[dir containing ZIP/CAB files and Java classes]" ARCHIVE="sneakers.zip"> <PARAM NAME="CABBASE" VALUE="sneakers.cab"> </APPLET> On your web server, you might organize the applet as follows:

   java/sneakers/        (Sneakers directory)
     index.html             (Sneakers home page)
     my_classes/           (directory containing classes and archives)
       sneakers.cab          (used by Internet Explorer)
       sneakers.zip          (used by Netscape)
       sneakers/             (sneakers package, for other browsers)
         game/                 (sneakers.game package, for other browsers)
           Applet.class
           Meteor.class
           ...
         sound/                (sneakers.sound package, for other browsers)
           Bang.class
           Bop.class
           ...
       highscore/            (highscore package, for other browsers)
         NewHigh.class
         ShowScores.class
         ...
In order to load this applet, you would have to copy the APPLET template that JPack produced into java/sneakers/index.html, and modify it to read:

<APPLET CODE="game.Applet.class" WIDTH=300 HEIGHT=500 CODEBASE="my_classes" ARCHIVE="sneakers.zip"> <PARAM NAME="CABBASE" VALUE="sneakers.cab"> </APPLET>

5. FAQ

1. What does JPack do?

JPack is a DOS application which automates the process of building CAB/ZIP archives for Java applets.

2. Who are you?

My name is Adam Doppelt. I'm a Senior at Brown University, majoring in Computer Science. I'll be graduating in May 1997, so my home page and email might be moving. My home page is currently at:

3. Why did you write JPack?

Recently, I was trying to figure out how to create these archives. It was a pain in the neck. I originally had a JPack batch file to do it, but it wasn't smart enough. I decided to crack the old Turbo C++ and write something better.

It only took a few minutes, but when it was done I figured other people might get some use out of it. Also, it would be useful to have a site which explained how the process worked and have pointers to more information.

4. Why does JPack complain that it can't find ZIP.EXE or CABARC.EXE?

JPack doesn't actually create the archives itself. Instead, it uses ZIP.EXE to create the ZIP archive and CABARC.EXE to create the CAB archive. Yes, it's true - JPack is basically just an intelligent batch file.

You need these two programs in order to use JPack. You can find pointers to them at the JPack home page:

5. Why can't I use Pkzip 2.04g instead of ZIP.EXE?

Pkzip 2.04g is a great program, but it doesn't support long file names. That's why we need ZIP.EXE.

6. What does all that crazy JPack output mean?

You are seeing the output as JPack does its work. JPack first calls CABARC.EXE, and then ZIP.EXE. If you look carefully, you can actually spot the command lines used to call those two applications. Maybe you don't need JPack after all, eh?

7. Why can't my browser find the ZIP or CAB archive?

Make sure that you've put the ZIP and CAB archives in the directory specified as the CODEBASE parameter to your applet. Remember that browsers interpret the string as a relative path, starting with the location of the current web page.

8. What happens if a particular browser doesn't support either archive format?

If a browser doesn't support either format, it will ignore both the ARCHIVE and CABBASE parameters to the applet, and attempt to load the applet in the usual manner. The "usual manner" means looking for classes and packages in the CODEBASE directory. See the examples above for more information.

9. How to I check to see what's in the archives?

To view the contents of a zip archive, type:

To view the contents of a cab archive, type:

10. You refer to Java "packages". What are they?

Java organizes classes into "packages", similar to a directory in a file system. For example, "java.awt" contains all of Java's awt classes. Java uses packages to organize classes logically (using import/package statements) and also to arrange classes on disk. For more information, check out the Java Package Tutorial:


Back to The Old Stuff, or maybe you want to mail Adam.