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.

 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 34
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%.

IBM Brings Developers Into the Cloud
Apache at 10: You Can't Buy Us
Microsoft's CodePlex Foundation Moving Forward
Apple Claims 100,000 Apps, Google Analyzes Them
Nokia Latest to Play Opera Mobile 10 Browser
PayPal Opens Up Payment Platform to Devs
Ubuntu Linux 9.10 'Karmic Koala' Starts Its Climb
IBM Links Rational Developer Tools, Tivoli Apps
Libraries Give Vista Apps a Windows 7 Look
Ubuntu: The 'Default Alternative' to Windows?

Delivering Web-based Embedded Fonts in CSS 3
Adobe Helps PHP Developers Create Rich Internet Applications
Java Developers Finding a Home at Adobe Flex
Virtualization Delivers a Dynamic Infrastructure
Consuming XML Web Services in iPhone Applications
Build a More Agile Business with IBM
POJO-Based Solutions for LDAP Access: One Good, One Better
IBM Offers Enhanced Measurement and Management for Energy Usage
IBM Helps Transformation to an Information-Based Enterprise
Top Five Touch UI-Related Design Guidelines

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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs