Microsoft KB Archive/241814

= SAMPLE: Download Java Applets that Require Other Java Classes =

Article ID: 241814

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Visual J++ 6.0 Standard Edition

-



This article was previously published under Q241814



SUMMARY
Often a Java applet may need some other Java classes to be available on the client's machine. If the client's machine does not have these classes installed, the Java applet generates a ClassNotFoundException error.

While it is possible for the supporting classes to be bundled within the Distribution Unit (DU) that contains the applet, often it is useful to unbundle the applet classes from the supporting classes for increased flexibility with respect to packaging and versioning. For example, by creating a separate DU for relatively stable library classes, once that DU is installed on the client's machine, it will not have to be downloaded until is has a version change. The DU that contains the applet classes may undergo many version updates during its early lifecycle so it would want to be packaged separately. It usually is a good idea to package third- party libraries separately for the same reasons.

This article describes how you can download Java classes that are needed by an applet and be sure that those classes are available before the applet starts.



MORE INFORMATION
The following file is available for download from the Microsoft Download Center:

MultiDU.exe

The sample is contained in the self-extracting file, MultiDU.exe. When you download and execute this file, it installs the sample files on your machine at the location you specify. The sample is a Visual J++ 6.0 solution containing four projects: the applet (MyApplet), three projects that are packaged as signed CAB files (One, Two, Three), and two HTML files (DUs, Applet). Each of the CAB file projects (One, Two, and Three) contain a class that is used by the Applet.

Use Visual J++ 6.0 to build the solution. Once built, you can use Internet Explorer to open the DUs.htm file. This file contains three applet tags that download each of the three DUs; you will be asked to accept the test certificate for each DU. Once that page is loaded, then the DHTML window.onload script event handler method gets called to load the applet page. This method gets called only after all applet tags have been processed (and thus all classes have been installed from the CAB files).

The Applet uses the three classes that were downloaded and installed by the DUs page. If one of those classes is not found (for example, you chose not to accept one of the certificates), then an appropriate error appears.

