Building a ZIP Archive
-
The first archive you will want to build is the ZIP archive. ZIP is the
oldest, and hence most supported format of the three so it should be easy
for you to find a ZIP archive generation program for whatever platform
you are working with. When choosing a ZIP utility program however, you
should be careful to choose one that support non-8.3 filenames since Java
class files usually have names which are longer.
-
I recommend the popular Shareware product WinZip which is available for
easy download at winzip.com. Regardless,
every ZIP utility should have a similar interface and options so if you
are not using a Windows box, you can still get the basic idea from the
following discussion.
-
The first step in creating a ZIP archive is to gather all of the class
and supporting files necessary to execute your applet into the package
structure defined in your Java code. This should be fairly simple since
in order to compile your Java files, you should have created a directory
structure mirroring your package structure on your local machine.
-
Once you have prepared your Java files to be archived, you should drag
the top-level directory into WinZip.
-
You can also use your right mouse button to click on the MyApplet directory
in Windows Explorer and choose "Add to Zip" from the popup menu
-
When you submit the top-level directory to WinZip, the "Drag and Drop Dialog"
should appear and give you several options for archiving. For the most
part, the archiving options should be fairly straight forward, but we will
present a laundry list for your convenience here. The options should be
set as follows:
-
Select a name for your ZIP archive using the "Add to Archive" Text Field.
-
Set the level of compression to "none" using the "Compression" Drop Down.
-
Instruct WinZip to archive all files and all files within directories by
toggling the "Recursive Folders" check box in the "Folders" Group.
-
Once you have set the options, hit the "Add" button and let WinZip do its
magic. In a few moments, WinZip will finish archiving your applet. Make
sure it recursively adds the directory structure
-
However, you are not quite done yet. Actually, there are several files
in the archive that do not need to be there. For example, the .html, all
of the .java files, and all of the .txt files. After all, the web browser
only needs the class files, and images to execute. Thus, the final step
in preparing the ZIP archive is to delete all of the extraneous files using
the "Actions | Delete" choice from WinZip's menu.
-
When you have deleted extraneous files, you can then upload your ZIP archive
to your web server and make it available to web browsers using the ARCHIVE
attribute such as in the following example:
<APPLET CODE = "MyApplet.class"
ARCHIVE = "MyApplet.zip"
WIDTH = "140" HEIGHT = "140">
</APPLET>
Notice that you must still reference the base class in the CODE attribute
even though it is contained in the ZIP file. After all, the web browser
must still know where to begin. More importantly, browsers that cannot
read ZIP files must still have access to the value of CODE.
Additional Resources:
Preparing
your Applet for the Web
Table of Contents
Building a Cab File
|