Using JAR Files with HTML
Since JAR files allow us to package a collection of files into one, and to compress the archive, they offer the opportunity to improve the download performance of applets that are retrieved from the Web via HTTP transactions. Basically, we can download the entire archive file in a single HTTP transaction. This reduces the number of trips we must make over the network to get all of the classes and associated files needed for an applet. Without an archive, multiple HTTP transactions may be required to download the required class files. There is also a performance boost because the archive can be compressed, reducing the download time.
The ARCHIVES Attribute
The ARCHIVES
attribute is used in the HTML file to
indicate that an archive file is used. The filename is relative to
the location of the HTML page. Let’s look at the HTML file we
used for running the PickleUser
applet from the
previous chapter:
<APPLET ARCHIVE="BeansBook.jar" CODE=PickleUser.class WIDTH=350 HEIGHT=125> </APPLET>
The ARCHIVES
attribute specifies that the
BeansBook.jar archive file should be downloaded.
Class files will be searched for in the specified archive first. If
the class is not found in the archive, then the normal mechanism of
searching the server and local file system will be used. Notice that
the CODE
attribute is still used to specify the
starting class for the applet.
When you run this HTML file with appletviewer, the
PickleUser
class will be loaded from the archive. The applet ...
Get Developing Java Beans now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.