Get 3.9% APR, Get Instant Credit - Click here!

PC Magazine

  PC Tech

Java Archives in Java 1.2

Introduction

Working With Java Archive Files

Using Archived Applications and Applets

Bye-Bye, <applet>, Hello, <object>

Figure: Java Archive Commands



X10.com - The SuperSite for Home Automation!

NextCard Visa- 2.9% intro APR -Apply Now

 
  Categories
Programming

Java Archives in Java 1.2
Using Archived Applications and Applets

Continued from Working With Java Archive Files

Thanks to the JAR enhancements to Java 1.2, you can now run archived applets and applications. If you pass the Java interpreter the -jar command, for example, you can run archived applications. Java applications packaged in JAR files can also be executed directly on the Windows or Solaris desktop.

How the automatic execution of archives works depends on the type of system you're using. When you install the Java 1.2 Runtime Environment on a 32-bit Windows system, the installation program registers a default association for JAR files. You can then run JAR files automatically by invoking the Java interpreter with the -jar option. For Solaris 2.6, Sun actually extended the kernel so that the operating system would recognize JAR files. The kernel extensions allow Solaris 2.6 to invoke the Java interpreter directly with the -jar option, and in this way Solaris systems can execute archive files as if they were native Solaris executables.

Working with archived applets is a bit different from running an archived application, because you need to tell the Java applet viewer or Java-enabled browser how to use an applet. Normally, you do this by creating a Web page that contains the <APPLET> tag. This tag has attributes that let you tell the browser about the applet, such as its class name and its location.

Using the <APPLET> tag, you can associate one or more archives with an applet. When you use archive files with applets, the browser always looks first in the archives for the necessary class and resource files. If the browser can't find these files in the archives, the browser then tries to obtain the files from the server--just as it would if the archives weren't present.

The attribute you use to specify that an applet's in a Java archive is aptly named ARCHIVE. The ARCHIVE attribute is always used in conjunction with the CODE attribute. The CODE attribute specifies the name of the main applet class, and the ARCHIVE attribute specifies the location of the archive, which can be defined as a relative or absolute URL. For relative URLs, your browser uses the applet's code base to determine the location of the archive. As you may recall, the code base is simply the location of the applet's source code, which can be specified with the CODEBASE attribute.

In the following example, the main applet class is myapp.class, and the browser looks for it in the associated archive file. If the browser cannot find the applet class, the browser then looks on the server for the applet class.

<APPLET CODE="myapp.class"
ARCHIVE="myapp.jar"
WIDTH="250" HEIGHT="250">
</APPLET>

If an applet uses more than one archive, you can enter the URLs for the archives in a comma-separated list. In the following example, the applet uses two archives. The first archive is called strider1.jar, and the second archive is called strider2.jar.

<APPLET CODE="strider.class"
ARCHIVE="strider1.jar, strider2.jar"
WIDTH="300" HEIGHT="300">
</APPLET>

Next: Bye-Bye, <applet>, Hello, <object>

Published as Internet Builder in the 2/23/99 issue of PC Magazine.

 
 SPONSORED LINKS
@Backup   Your Solid Online Backup Plan. Download Now.
Services   9c/MINUTE LONG DISTANCE, 5c/MINUTE ON SUNDAYS!
STORAGE   Quantum means non-stop business, 24 hours a day
Software   X10.com -- The SuperSite for Home Automation
Books   Bargain Books up to 90% off at barnesandnoble.com
 ZDNET FEATURED LINKS
Downloads   Check out the best new downloads in Reviewer's Raves
Bargains!   Shop the Basement for best buys on computer products
Free Help   Got computing questions? ZDHelp has all the answers!
 MAGAZINE OFFERS
Free Offer   Get a FREE SUBSCRIPTION to Inter@ctive Week

TOP
Copyright (c) 1998 Ziff-Davis Inc.