Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Obsolete since Gecko 16.0 (Firefox 16.0 / Thunderbird 16.0 / SeaMonkey 2.13)
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Summary

A top-level object used to access Java classes from within JavaScript code.

The support for this object was removed in Gecko 16, see LiveConnect for details.

Created by

The Packages object is a top-level, predefined JavaScript object. You can automatically access it without using a constructor or calling a method.

Description

The Packages object lets you access the public methods and fields of an arbitrary Java class from within JavaScript. The java, netscape, and sun properties represent the packages java.*, netscape.*, and sun.* respectively. Use standard Java dot notation to access the classes, methods, and fields in these packages. For example, you can access a constructor of the Frame class as follows:

var theFrame = new Packages.java.awt.Frame();

For convenience, JavaScript provides the top-level netscape, sun, and java objects that are synonyms for the Packages properties with the same names. Consequently, you can access Java classes in these packages without the Packages keyword, as follows:

var theFrame = new java.awt.Frame();

The className property represents the fully qualified path name of any other Java class that is available to JavaScript. You must use the Packages object to access classes outside the netscape, sun, and java packages.

Properties

className: The fully qualified name of a Java class in a package other than netscape, java, or sun that is available to JavaScript.

java: Any class in the Java package java.*.

netscape: Any class in the Java package netscape.*.

sun: Any class in the Java package sun.*.

Examples

Example: JavaScript function to create a Java dialog box

The following JavaScript function creates a Java dialog box:

function createWindow() {
   var theOwner = new Packages.java.awt.Frame();
   var theWindow = new Packages.java.awt.Dialog(theOwner);
   theWindow.setSize(350, 200);
   theWindow.setTitle("Hello, World");
   theWindow.setVisible(true);
}

In the previous example, the function instantiates theWindow as a new Packages object. The setSize, setTitle, and setVisible methods are all available to JavaScript as public methods of java.awt.Dialog.

Document Tags and Contributors

Tags: 
 Contributors to this page: fscholz, Nickolay, Sheppy, Sevenspade, Mgjbot, Callek, Maian, JamesRoss, Marcoos, Dria
 Last updated by: fscholz,