Java and Tcl

Java and Tcl do actually work together, and can be combined in interesting and useful ways. To get a more complete list of references, go to the Category Java page, click on the title, and you'll get a list of pages that refer to the Java Category.


The most notable combinations of Tcl and Java are described as part of the TclJava project.

  • Jacl is a Tcl 8.x interpreter written in Java. You can script your Java applications in Tcl.
  • TclBlend is an extension that allows you to code new Tcl extensions in Java.
  • Swank is a graphical toolkit for Jacl, allowing Java programs to code against the Tk widget set.
  • Hecl is a language very similar to Tcl implemented in Java.

2010-11-27 The Jtcl Interpreter, a fork of Jacl has been released, which continues the modernization of Jacl to support Tcl 8.4 commands.


How to Install and Use Jacl, TclBlend, and Swank

You will need a JRE (Java Runtime Environment) to run any of these. The JRE is a free download from Sun, at http://java.sun.com/j2se/

The easiest way to try out any of these projects is to make sure you have a JRE version 1.4.2 or higher, download Swank, and follow the instructions in the README.txt. The download from the Swank site is prebuilt class files, and also includes the prebuilt class files for Jacl and TclBlend.

The downloads from the Jacl and TclBlend sites are the Java source for these projects. You will need a JDK (also free from Sun) to build the "binaries" (Java bytecode classes) from this source. If you are using JDK 1.5 to build version 1.3.1 of Jacl or TclBlend, then before running make, you will need to edit the makefile and add "-source 1.4" to the JAVAC_FLAGS setting: e.g.

 JAVAC_FLAGS = -g -source 1.4

The source for Swank is available from CVS.

To use TclBlend, you also need to download the source for Tcl (and any other extensions you need), configure Tcl to build it for threads, and then build and install it in a new directory. Then, configure and build extensions similarly. Note that not all extensions may be thread safe - alas, I don't know of a way to determine other than trying things out and seeing if they crash.

escargo 2008-11-21 - Would it be possible to tell if a particular environment already had properly configured and built Tcl available? When you "install it in a new directory," does that mean if your system already has Tcl prebuilt, you must install thread-enabled Tcl in a different directory? Or is the presumption that you don't have Tcl installed, so that when you install it, you must create a directory to hold it?


If you want see contrasts and comparisons between Java and Tcl, then you might want to look at Java vs Tcl or just the Java page.


asidin - 2011-12-05 03:33:52

I couldn't find a way to load a dll to either of these options since jacl and jtcl doesn't support the load command. Can anyone advise ?

DKF: The load command isn't supported because it can't work in anything like the same way inside a JRE (though tclblend can do it, as that embeds Java inside Tcl and not the other way round). Instead, define extension code in Java and load it through invoking Class.forName() (etc.) all of which you can do through the mechanisms already present. (You could make the class that you load also pull in some native code via JNI, but that's a non-Tcl approach so we don't document it here; from the Jacl perspective, it will still look like Java calls.)