Java Package


Loading into Tcl interpreter:

package require java ?version?

package require java loads the java package into the interpreter. The java package provides an interface for creating and manipulating Java objects via object handles. Object handles are references to Java objects in Tcl. Many of the commands in the java package take arguments and return values that are object handles.

Before you can use the java commands you must load the java package by executing a package require java command.

When the java package is loaded into a Tcl interpreter (Tcl Blend), a JVM will be created in Tcl's process space.

When the java package is loaded into Jacl, each of the java commands will be created inside the Jacl interpreter.

When a JDK 1.2 JVM is created by Tcl Blend, the global variable tclblend_init is read and each list element is passed as an option to the Java Virtual Machine.

Example values include:
-Djava.compiler=NONE
disable Just In Time Compiler
-Djava.library.path=c:\jdk\lib\tools.jar
set native library path on a Windows system
-verbose:jni
print debugging messages

For -verbose, the value should be a string with one or more comma separated names (i.e. class,jni). In JDK1.2 the standard names are: class, gc, jni To see what other options are available, run java -help from the command line.

In addition tclblend_init can have the following values:

help
Print a help message and then stop JVM initialization.
debug
Print out debugging messages when the package is loaded.

To use tclblend_init, set it before loading the java package:

set tclblend_init -verbose:jni
package require java
Note that tclblend_init is read only if the Tcl Blend C shared library was compiled with JDK1.2.

Loading into Java:

Tcl Blend can now be loaded into an existing JVM. When an instance of the tcl.lang.Interp class is created from Java, the shared libraries for both Tcl and Tcl Blend will be loaded into the JVM's process. All that is required is to make sure that the system shared library paths are set properly and that both tclblend.jar and tcljava.jar appear on the classpath. This exciting new functionality was one of the most commonly requested features. Supporting it required re-implementation of most of Tcl Blend, so we hope you enjoy it.

Copyright © 1997-1998 Sun Microsystems, Inc.