Building a Cab File
After you have created your ZIP archive, you can then create a CAB (CABinet) file that will contain your compressed and archived applet for Microsoft's Internet Explorer users. Building CAB files is a little less user-friendly than building ZIP files, since there is no graphical interface like WinZip for creating CAB files.
Instead, you will have to use the command line interface provided by CABARC. CABARC is a compression/archiving program distributed with Microsoft's SDK located in either the "bin" directory under your main SDK directory or the "bin/packsign" directory.
CABARC follows the generic format:
CABARC [options] command cabfile [@list] [files] [dest_dir]
Options and Commands are summarized in the following table:
| Parameter |
Command |
| L |
Used to list the contents of
a cabinet |
| N |
Used to create a cabinet
file |
| X |
Used to extract single or
multiple files from the cabinet |
| Options |
| -c |
Confirms the files to be
operated upon |
| -o |
Overwrites without
confirming when extracting |
| -m |
Sets the type of compression
to use to LZX:<15..21>, MSZIP, or NONE. The default is MSZIP |
| -p |
Used to preserve path
names |
| -P |
Used to strip a specified
prefix from files when they are added |
| -r |
Used to recurse into
subdirectories when adding files |
| -s |
Used to reserve space in the
cabinet for signing. For example, -s 6144 reserves 6k. |
| -I |
Used to set the ID of the
cabinet when creating a cabinet. The default is 0. |
CABARC Commands
As you can see, there are several commands supported by CABARC. You can list files, add files, and remove files from cabinets.
Since you will be most interested in creating CAB files, you will be primarily using the "N" command. For example, the following CABARC command would create a CAB file called "MyApplet.cab" that would contain all of the class files in the current directory:
cabarc N MyApplet.cab *class
CABARC also allows you to list the files in a current cabinet. In this case, you will use the "l" command as follows:
cabarc L MyApplet.cab *class
The "L" command returns information about the size of each file in the cabinet -- the dates and times each was added, as well as the attributes of each file.
CABARC also allows you to selectively remove files from a cabinet using the "X" command. For example, to remove the SupportClass.class file from the example above, we would use the following syntax:
cabarc X MyApplet.cab SupportClass.class
Notice that when extracting files, the default behavior is for CABARC to ask you if you would like to overwrite existing files, if they have the same name as those being extracted.
CABARC Options
You will most likely specify options when performing actions with CABARC. For example, consider the MyApplet example we have been using so far in this chapter. The MyApplet program actually contains several files and several directories. Unfortunately, as shown above, if you simply use the "N" option to create your archive, you will not be able to add all these files and directories in one simple line. You would have to add each directory and file separately.
Fortunately, CABARC provides the -r option to add files to a CAB archive recursively. Thus, to create a functional CAB archive for our applet, we would want to use something along the lines of
cabarc -r N MyApplet.cab *
As you can see, the -r option will add all of the files and all of the subdirectories necessary for our cabinet file. However, the -r option will add files that are not necessary such as the .txt , .java and .html files. In order to make your CAB archive as small as possible, you will want to only add the necessary files.
To do so, you can specify the list of files to add using something like the following:
cabarc -r N MyApplet.cab *class *.jpg, *.gif
In this case, you will only get files with the specified extensions.
Referencing Your Cabinet
However, you are not quite done yet. Once you create your cabinet, you must then upload it to your web server and make it available to web browsers using the CABBASE parameter as follows:
<APPLET CODE = "MyApplet.class" ARCHIVE = "MyApplet.zip"
WIDTH = "140" HEIGHT = "140">
<PARAM NAME = "cabbase" VALUE = "MyApplet.cab">
</APPLET>
In this case, Internet Explorer will parse the parameter and access the cabinet file.
NEXT
Selena Sol contributes to the JavaBoutique's Introduction to Java. Selena curently works for Barclays Capital in London, one of the leading global investment banks in Europe and has worked as a software developer for the National Center for Human Genome research, Microline Software, Neuron Data, and Electric Eye in Singapore. Selena is perhaps best-known for creating the Public Domain Web Script Archive (Extropia) and writing several books on Web Programming (Perl, CGI, Java).
Email: selena@extropia.com
|