advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Articles : JavaBoutique's Introduction to Java :
Constructing .Zip, .Cab, and .Jar Files :

Contents
Building a .Zip Archive
Building a .Cab File
Building a .Jar File

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

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs