Updated 2012-12-17 21:03:14 by AMG

http://tcljava.sourceforge.net/ is the home of Jacl. Jacl is an alternate implementation of Tcl 8.x, written entirely in Java. Jacl is production ready software, and it is stable enough to be used in production systems on a daily basis.

Jacl was last released, during April of 2008, as version 1.4.1 . (See Jacl modernization for current work.)

Jacl and TclBlend are both implementations that make it easy to use Tcl scripting on the Java platform. The Tcl/Java project provides mailing lists [1], online documentation [2], and a bug reporting interface [3].

Links to a number of Jacl and TclBlend related articles are also available [4].

For help building Jacl under Windows, see Building JACL with msys.

Not to be confused with JACL Adventure Creation Language [5]: "JACL is an interpreted computer language originally designed for creating interactive fiction."

According to this 2003 InfoWorld article[6], Sun was thinking of introducing scripting to Java. Shouldn't they be encouraged to do this with Tcl? - escargo 12 Jun 2003 (The linked page did not display well with IE, but did with Mozilla.)

LV Sun has nothing to do with Tcl ... it has been long enough that the people still working there may not even remember that there was ever a Tcl and Sun connection.

It'd be great however if some of the Java heavies got on the Jacl band-wagon.

Swank is an interesting extension to Jacl. It was last updated during 2007.

CL occasionally updates a page [7] of information related to Jacl. Note that much of the information on this page is out of date.

Has anyone figured out a way for Jacl apps to communicate with tcl/tk apps via a send like mechanism?

There is no support for send in Jacl.

For an informal comparison of how Jacl fared in a 2003 vote for favorite Java scripting language, check http://viva.sourceforge.net/republic/2004/01/scripting_language_of_the_year_2003_award_and_the_winner_is.html

schlenk With only 480 votes this can be hardly seen as relevant, perhaps we should hold such votings for Tcl too...

Summer 2004: "Tom Poindexter is working on a companion to Jacl (called Hyde) that compiles Java on the fly ..."

Running JACL under IBM RAD 6/Eclipse 3.1.

Patrick Finnegan 13/07/2005.

Someone at work asked me how to do this so here are some concise instructions with a trivial example for anyone else who wants to experiment with RAD6 or Eclipse 3.1.

Download RAD6 trial from:

http://www-128.ibm.com/developerworks/downloads/r/rad/?S_TACT=105AGX14&S_CMP=DWNL

Start RAD6 or Eclipse 3.1.

  1. Create Java project.
  2. Add the JACL jar files.

Add jacl.jar and tcljava.jar to the java build path under "project properties". The jar files are already packaged with RAD6 and can be found under the install directory e.g. "D:\IBM\Rational\ADTrial\6.0\runtimes\base_v6\lib\jacl.jar".

  1. Create a top level java class.

Create a top level java class with a main method. Instantiate the tcl interpreter and use the Interp eval method to either run Tcl in-line or source Tcl from a file.

Example.

  1. Run the tcl command in-line "puts [clock format [clock seconds] -format %k:%M:%S]"
  2. Source the proc compare.
 proc compare {howmany value} {
   for {set i 1} {$i < $howmany} {incr i} {
      if {$i == $value} {
         puts $i
      }
   }
 }

 set bench 1000

 set bench2 [expr $bench - 1]

 puts "comparing an int against $bench others..."

 compare $bench $bench2

 ##############################################################################

 import tcl.lang.*;

 // Java wrapper to test JACL under RAD 6.

 public class ScriptRunnerTcl {
    public static void main(String []args) {

        Interp i = new Interp();

    try {

            i.eval("set x {The time is }");
            i.eval("set y [clock format [clock seconds] -format %k:%M:%S]");
            i.eval("puts [append z $x $y]");
            i.eval("puts \\n");
            } catch (TclException e) {
            System.out.println("Exception: " + e.getMessage());

            }

        try {
            i.eval("source E:/scripts/TCL/jacl/compare.tcl");
            } catch (TclException e) {
            System.out.println("Exception: " + e.getMessage());
            }

    }
 }

 #############################################################################

The output looks like:
 The time is 21:19:51

 comparing an int against 1000 others...

 999

BSF and JACL

BSF is the Bean Scripting Framework [8] -- a way of adding a scripting engine to Java (or to call Java from a scripting engine).

While there are some references that describe how to use it ([9], [10], [11], and [12] among others), none of them read clearly and concisely enough (at least for one user).

In short

  • Download the BSF jar from Jakarta: [13].
  • Download the Tcl/Java sources from sourceforge: [14]
  • Build the JACL and TclJava jars (configure, make)
  • Add the jars to the classpath (in Eclipse, add them to the Project Properties -> Java Build Path -> Libraries)
  • Add an import for the BSF engine to the Java class where you wish to embed JACL:
 import org.apache.bsf.*;

  • Add code in the Java application to read the script file, then pass it as a string to the BSF manager:
            try {
                BSFManager mgr = new BSFManager ();
                Object r = mgr.eval("jacl", scriptFile, 0, 0, script);
                theUI.addLogText( "Return value: " + r.toString() + ", " + r.getClass().getCanonicalName() );
            } catch(BSFException bsfe) {
                bsfe.printStackTrace();
            }

where "scriptFile" is the name of the file containing the script and "script" is that file's contents; the addLogText method on some Java UI object adds the text to a log window in the UI.

  • Read in the following "jacl" script and use the Java code above to interpret it:
 package require java
 puts "Hello world"
 return "Heellllo, world"

  • And "Hello world" shows up in the Java programs STDIO while the following line appears in the UI's log window:
 Return value: Heellllo, world, java.lang.String

Where at least one user went wrong was neglecting to add the TclJava jar to the class path, as well as the JACL jar (even though only JACL was all that was used, both jars were needed-- a tip which someone else thankfully put into a c.l.t. posting here: [15]).

IL 7-5-2006 Has anyone run Jacl under JDK 1.5? I'm wondering if any of the post 1.4 features have broken it. If not, I'm going to start playing around with this, maybe in the context of an Eclipse plugin. Also with JDK 1.6 around the corner, I'm interested in seeing how the new scripting features could better integrate my TCL and Java... btw, shouldn't the proper name for this be TCL4j? sounds cooler ;)

Someone help me through some of the basics here... I have hello world, but how should I treat the interpreter? Should you keep around one copy and reuse the interp object over and over? Does anyone have any "template" projects for this they'd be willing to share? This seems fun beginning to mesh together, I'm wondering what I can do now that I can left hook with TCL and right hook with Java :)

IL 11-1-2006 : Interp, where can find the appropriate usage of this class? I'm considering embedding Jacl in Tomcat 5.5.17, and I'm wondering how to set it up for proper multi-threading and a base common interpreter that is copied into pools which are available to handle on request... I guess I could mess around with it, but I'm hoping someone has answers :)

NEM: Probably best to also ask on the tcl-java mailing lists, as I'm not sure if key people are frequent wiki visitors.

NEM has an initial implementation of dict for Jacl, available as a patch at [16]. Most of the functionality is there, but there are some memory leaks. IIRC, plugging the remaining leaks and improving performance would require a custom hashtable implementation (I just use java.util.HashMap at present). If anyone has the time to polish it off...

Chi Hung Chan Sun Java System Web Server 7.0 [17] came out with a revamped command-line interface that incorporates a scripting framework. This scripting framework is based on JACL a java-vm implementation of the TCL language. Interestingly, the team evaluated other scripting languages like Ruby, Perl, Python, but chose Tcl/Jacl.

escargo 9 May 2007 - Is this the same as JavaFX Script [18]? There is no hint that the announced scripting language is based on Jacl. At the very least, they added an object layer on top of it. (It's not clear yet what kind of object system they provide.) Looking a little deeper [19] it doesn't sound like Jacl at all:

"JavaFX Script is a declarative, statically typed programming language. It has First-class functions, declarative syntax, list-comprehensions, and incremental dependency-based evaluation. It can make direct calls to JavaAPIs that are on the platform. Since JavaFX Script is statically typed, it has the same code structuring, reuse, and encapsulation features (such as packages, classes, inheritance, and separate compilation and deployment units) that make it possible to create and maintain very large programs using Java technology."

TP Two different things. Sun java Web Server 7.0 uses Jacl, heavily extended to include commands to control every bit of the server:
 $ wadm --user=admin
 Please enter admin-user-password>
 Sun Java System Web Server 7.0 B12/04/2006 08:17
 wadm> lsort [info commands]
 add-documents add-webapp after append array auto_execok auto_load auto_mkindex auto_reset binary
 block-reverse-proxy-header    break case catch cd clock close concat continue copy-config copy-virtual-server
 create-auth-realm create-auth-realm-userprop  create-authdb create-authdb-userprop create-cert-request
 create-cgi-dir create-cgi-envvar create-config create-custom-resource create-custom-resource-userprop
 create-dav-collection create-document-dir create-event create-external-jndi-resource
 create-external-jndi-resource-userprop create-file-authdb create-group create-group-member
 create-http-listener create-instance

 ..etc..

JavaFX Script is a new language on top of the JVM. If you want to program GUI's in Jacl with a Tk-like interface, see Swank (desktop apps) or Aejaks (webapps).

escargo - I see. Sun wasn't content to add one new scripting language to Java; they had to add two, aimed at different audiences. The mind boggles.

http://blogs.sun.com/blue/entry/scripting_with_servlets_jacl_part discusses use of Jacl with the Sun Java System Web Server.

LV 2007 June 26 Anyone know of freely (or commercially) available Jacl/TclBlend tutorial material other than the two or three brief IBM articles and one or two aged journal articles?

Sarnold I want to mention TJC (paper by Mo DeJong here: [20]). In short, it is a kind of Jacl proc to Java class compiler, giving Jacl enough power to be comparable to Tcl's C implementation. Some benchmarks show Jacl as close to Jython performances. See this page: [21].

See also