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 Zip Archive

The first archive you will want to build is the ZIP archive, the oldest and most supported of the three. For this reason, it should be easy for you to find a ZIP archive generation program for whichever platform you are using. When choosing a ZIP utility program, however, you should be careful to choose one that supports non-8.3 filenames, since Java class files usually have names which are longer.

I recommend the popular Shareware product WinZip 95, which is available for easy download at http://www.jumbo.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 you need to create a directory structure mirroring your package structure on your local machine in order to compile your Java files.

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 straightforward, 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, including all the .html, .java, and .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, 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.

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

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 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