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

 DevX Skillbuilding from IBM developerWorks
 RIA Run Contest: Build Next-Gen Apps in Microsoft Silverlight 2
 Avaya DevConnect Center
 Intel Go Parallel Portal
 Internet.com eBook Library
 Microsoft RIA Development Center
 Destination .NET
XML error: not well-formed (invalid token) at line 53
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%.

RIM Ups Ante With Mobile Software Push
Novell Readies Silverlight Clone for Linux
Yahoo Pitches The 'Next Generation of Search'
Alfresco's Latest ECM: Prying Open a Sector?
SaaS Tool Offers Custom Database Development
Microsoft’s Automated Agent: Can We Talk?
Borland Finally Sells CodeGear
Red Hat Heads for the JON 2.0
Out with the Old, in with the New at JavaOne
Trolltech Expands WebKit Footprint

Create Secure Java Applications Productively, Part 1: Use Rational Application Developer and Data Studio
.NET Building Blocks: Custom User Control Fundamentals
Secure Internet File-Sharing with PHP, MySQL, and JavaScript
Getting Started with TBB on Windows
Moving to VoIP: Should You Go It Alone?
Introduction to the WPF Command Framework
7.0, Microsoft's Lucky Version?
Will Hyper-V Make VMware This Decade's Netscape?
Eliminate Fragmentation Frustration with Netbiscuits
Taming Trees: Building Branching Structures

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



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: 7.0, Microsoft's Lucky Version?
Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Windows Server 2008
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES