This is the README file for the JavaScript LiveConnect Version 3 ("LC3") implementation.

Table of Contents

Introduction
New features
Compatibility
Limitations/Bugs/To-Do
Build conventions
Naming and coding conventions
The LiveConnect API
Sample LiveConnect shell interactions

Introduction

LiveConnect is a library that permits JavaScript and Java virtual machines to interoperate. Specifically, it enables JavaScript to access Java fields, invoke Java methods and enables Java to access JavaScript object properties and evaluate arbitrary JavaScript. LiveConnect was originally an integrated feature of both the Netscape Navigator browser and Netscape's server-side JavaScript. Now, it is a standalone library that can be embedded within other projects, such as the Mozilla browser. More information on LiveConnect can be found by searching the index on Netscape's DevEdge site.  This README assumes basic familiarity with JSRef, the reference implementation of JavaScript, and with the LiveConnect technology.

The JSRef project/makefiles (located in another directory) build a library or DLL containing the JavaScript runtime (compiler, interpreter, decompiler, garbage collector, atom manager, standard classes).  The LiveConnect project/makefiles build a library that links with both JSRef and any Java Virtual Machine (JVM) that implements the Java Native Interface (JNI), as specified by JavaSoft.  It then compiles a small "shell" example program and links that with the library to make an interpreter that can be used interactively and with test scripts.  See the sample shell interactions.

Scott Furman, 10/31/98

New features

The following features were not available in the versions of LiveConnect that were integrated with Netscape Navigator versions 4.x and earlier.  For information on LiveConnect version 1, which was used in Navigator versions 3 and 4, and Enterprise Server 3, see Netscape's DevEdge site or any number of 3rd-party publications.)

LiveConnect version 3 (8/31/99)

LiveConnect version 2 (7/31/98)

  • The Java methods of java.lang.Object are now invokeable methods of JavaArray objects, matching the behavior of arrays when accessed from Java.  (Java arrays are a subclass of java.lang.Object.) For example, Java's getClass() and hashCode() methods can now be called on JavaArray objects.  (In prior versions of LiveConnect, the methods of java.lang.Object were only inherited by non-array Java objects.)
  • Note that this change has caused the string representation of JavaArray objects to change.  Previously, the JavaArray toString() method always printed "[object JavaArray]" for all JavaArray's.  Now, the Java java.lang.Object.toString() method is called to convert JavaArray objects to strings, just as with other, non-array Java objects that are accessible via LiveConnect. java.lang.Object.toString()is defined in the Java Language Specification to return the value of the following expression:

    getClass().getName() + '@' + Integer.toHexString(hashCode())

     

  • A one-character string is now an acceptable match for an argument to a Java method of type char.  (In earlier versions of LiveConnect, the only acceptable match for a char had to be a JavaScript value that was convertible to a number.)  For example, the following is now possible:
  • c = new java.lang.Character("F")

     

  • A JavaClass object is now an acceptable match for an argument to a Java method of type java.lang.Class.  For example, you can now write:
  • java.lang.reflect.Array.newInstance(java.lang.String, 3)

    instead of the more verbose:

    jls = java.lang.Class.forName("java.lang.String")
    java.lang.reflect.Array.newInstance(jls, 3)


     

    Compatibility

    Unlike this standalone/component release, all previous versions of LiveConnect appeared only as an integrated feature of Netscape Navigator or the Enterprise Server.  The variants of LiveConnect that appeared in Navigator versions 3.x and 4.x all behave much the same, modulo bugs.  For brevity we refer to this classic version of LiveConnect as "LC1" (LiveConnect version 1) and this most recent release as "LC3".  With a few exceptions LC3 provides a superset of LC1 features. (There was an intermediate LiveConnect release known as "LC2" in 7/98, but it was not used in any products.)

    Limitations/Bugs/To-Do

    Build conventions

    The following directions are for building the standalone version of LiveConnect. To build the version that's used in the Mozilla browser, see the Mozilla build documentation.

    On all platforms, you must update your JVM's CLASSPATH to point to the js/src/liveconnect/classes subdirectory.  If you do not, LiveConnect will still operate but with the limitation that JS objects may not be passed as arguments of Java methods and it will not be possible to call from Java into JavaScript, i.e. the netscape.javascript.JSObject class will be inaccessible.  Another downside of operating without these classes is that Java error messages will not include a Java stack trace, when one is available.  If your CLASSPATH is set improperly, you will see a message like, "initialization error: Can't load class netscape/javascript/JSObject" when starting a LiveConnect debug build.

    By default, all platforms build a version of LiveConnect that is not threadsafe.  If you require thread-safety, you must also populate the mozilla/dist directory with NSPR headers and libraries.  (NSPR implements a portable threading library, among other things.  The source is downloadable via CVS from mozilla/nsprpub.)  Next, you must define JS_THREADSAFE when building LiveConnect, either on the command-line (gmake/nmake) or in a universal header file.  Note that JSRef must also be built with JS_THREADSAFE.

    One important note about building on Windows: There are two independent build systems (in addition to the Mozilla browser build system). One of them uses the IDE project files and the other uses gmake and makefiles. The former will be preferred by most for debugging and the latter is more complete, since it builds the necessary Java classes in addition to compiling the LiveConnect C code.

    Naming and coding conventions: