Core JavaScript 1.5 Guide:LiveConnect Overview:Java to JavaScript Communication
From MDC
If you want to use JavaScript objects in Java, you must import the netscape.javascript package into your Java file. This package defines the following classes:
-
netscape.javascript.JSObjectallows Java code to access JavaScript methods and properties. -
netscape.javascript.JSExceptionallows Java code to handle JavaScript errors.
See the Core JavaScript Reference for more information about these classes.
[edit] Locating the LiveConnect classes
In older versions of the Netscape browser, these classes were distributed along with the browser. Starting with JavaScript 1.2, these classes are delivered in a .jar file; in previous versions of JavaScript, these classes are delivered in a .zip file. For example, with Netscape Navigator 4 for Windows NT, the classes are delivered in the java40.jar file in the Program\Java\Classes directory beneath the Navigator directory.
More recently, the classes have been distributed with Sun's Java Runtime; initially in the file "jaws.jar" in the "jre/lib" directory of the runtime distribution (for JRE 1.3), then in "plugin.jar" in the same location (JRE 1.4 and up).
[edit] Using the LiveConnect classes with the JDK
To access the LiveConnect classes, place the .jar or .zip file in the CLASSPATH of the JDK compiler in either of the following ways:
- Create a
CLASSPATHenvironment variable to specify the path and name of .jar or .zip file. - Specify the location of .jar or .zip file when you compile by using the
-classpathcommand line parameter.
You can specify an environment variable in Windows NT by double-clicking the System icon in the Control Panel and creating a user environment variable called CLASSPATH with a value similar to the following:
C:\Program Files\Java\jre1.4.1\lib\plugin.jar
See the Sun JDK documentation for more information about CLASSPATH.
Note: Because Java is a strongly typed language and JavaScript is weakly typed, the JavaScript runtime engine converts argument values into the appropriate data types for the other language when you use LiveConnect. See Data Type Conversions for complete information.