TclJava is obsolete, use Tcl Blend instead.

Places to go:

  • The Sunscript Techcorner has a section about Tcl and Java.
  • Sun's Tcl/Java interface page.
  • Tcl Blend - Sun's Tcl/Java interface to Tcl8.0. Tcl Blend will be the replacement for Tcljava, no further work on Tcljava is planned.
  • Ken Corey's Talks and Papers, including a few on TclJava.
  • Ken Corey's TclJava Reference Manual
  • Distributing Objects across Java and Tcl/Tk Mark C. Reynolds, United Technologies
  • Jacl -- Tcl Interpreter for Java Ioi Lam, Cornell
  • jTcl - Java-like syntax in Tcl (Philippe Le Foll, Fridu, South Brittany University)
  • My Java Page

  • Sun's Tcl/Java interface, available at can be used to create a shared library that is loaded by the Java byte interpreter. This shared library has Java classes that allow the user to evaluate Tcl commands. We created a GNU autoconf file that allows tcljava to be easily configured.

    We are particularly interested in combining Itcl and Java for use in the Tycho project.


  • The original Tcljava interface:
  • Tcljava0.4a (gzipped tar file) patched for use with jdk1.1, configure and NT. - Patch to convert tcljava0.4 to tcljava0.4a
  • Itcl2.2 files that work with Microsoft Visual C++ (gzipped tar file). Itcl2.2.

  • Installing Tcljava under Unix

    I created a GNU autoconf configure script that can be used to configure tcljava. This script works under Solaris.
    1. Install tcl and tk by configuring with the --enable-shared option.
    2. You can either download a patched version of Tcljava (tcljava0.4a), or grab the original Tcljava interface from Sun and then patch it with the patch below.
      If you downloaded tcljava0.4a, then skip to step 5 below.
    3. If you are using the unpatched Sun tcljava0.4 sources, then grab the tcljava0.4a.patch, file which contains the following new files:
      Autoconf source file
      Shell script to run that configures the installation
      Makefile template that configure uses to create makefile
      Microsoft Visual C++ makefile for NT.
      The patch also contains a change to the following file:
      Apparently, in jdk1.1, The package does not exist. This package was present in jdk1.0.2. If you try to compile with the jdk1.1 javac, you will get Package not found in import.

      Fixed a bug where if the user hit the demo button, java would crash because a pathname was hardwired in.
    4. Untar the Sun tcljava0.4tar file and then patch it with
      patch < tcljava0.4a.patch
      while in the directory above tcljava0.4 directory.
    5. configure has a number of options to set the paths. You can use: configure -help to see them all.
      You will probably need to specify at least three arguments:
      You will probably need to use the --with-java option to tell configure where your Java installation is. If you java installation is at /opt/jdk1.1, then you would use .
      If your tcltk installation is not installed in the default location (/usr/local), then you may need to call configure with other arguments.

    Building Tcljava under NT

    I believe that to Install Tcljava under NT, you must rebuild Tcl from scratch. If you do not rebuild Tcl from scratch, then when you try to link with the tcl and tk dll, VC++ will complain about invalid objects.

    Why not gcc?

    I don't think that java native methods can be compiled under gcc, if you run javah, then the .c file that is generated has a line like:

    __declspec(dllexport) stack_item *Java_tcl_Interp_native_0005feval_stub(stack_item *_P_,structexecenv *_EE_) {
    I downloaded the cygwin gcc (version cygnus-2.7.2-961023), and it failed to compile this line, the error message was:
    	tcl_classes.c: In function `__declspec':
    	tcl_classes.c:8: syntax error before `{'
    I also had problems compiling c:\jdk1.\include\win32\typdefs_md.h, with gcc, there were errors in the INT_OP declaration. I also had problems __int64 in typdefs_md.h. Perhaps gcc can be used here, but I did not look into this any further.

    Installation procedure

    1. Download the Tcl/Tk sources. Locally, we use Itcl, an object oriented extension to Tcl/Tk, so these instructions are based on Itcl sources. The Itcl2.2 sources can be obtained from:
    2. I untar'd the Itcl2.2 sources in c:\Itcl2.2
    3. The Itcl2.2 sources need several fixes the the files. The itcl2.2a.tar.gz gzipped tar file contains the appropriate fixes. You should grab itcl2.2a.tar.gz and untar it over the Itcl2.2 distribution. itcl2.2a.tar.gz contains the following fixes:
      1. tk4.2/win/ needed the $(IWISH) rule changed to $(WISH).
      2. needed:
        	TKLIBDIR	= $(TKDIR)\Win
      3. itk/win/ needed
      4. Also, I fixed the installation rules so that make install will not fail if it is run a second time because mkdir fails.
    4. Build and install the Itcl2.2 distribution with:
      cd c:\Itcl2.2
      nmake -f dist
      nmake -f install
      Note that if you have already previously installed Tcl/Tk, you should remove any preexisting Tcl/Tk libraries, such as tcl76.dll or tcl76i.dll
      If you have the problem where everytime you run nmake, all the files are rebuilt, then try using the Cygnus chmod and touch commands to update the mod times on all the files. The problem I noticed was that many of the files are dated Dec 31, 1969.
    5. Download the Java Development Kit from I installed it in c:\jdk1.1
    6. Download tcljava0.4a (gzipped tar file). This file is based on tcljava0.4, but it has been patched for use with jdk1.1, configure and NT. I installed this as c:\tcljava0.4a
      I had to make the following changes to tcljava0.4:
      1. tkJava.c was failing to compile with lots of problems in rpcdce.h. The following small test program fails to compile:
        	int foo() { return 1;}
        The rule I used to test this was:
        		cl -Ic:\jdk1.1\include -Ic:\jdk1.1\include\win32 \
        		-I$(TOOLS32)\include $(TK_INCLUDES)  \
        		/c tst.c
        The fix is to insert
        /* NT4.0, vc++: If you don't undef Status, then rpcdce.h won't compile -cxh */
        #ifdef _MSC_VER
        #undef Status
        right before the line that includes oobj.h.
      2. JDK1.1 under Windows does not include the package, so I had to comment out a number of lines that tried to use it before the class would compile
      3. When linking, I got an error about perror not being defined, so I modified the to not define EXECHACK
      4. When trying to run java TclTest, I kept getting errors about create not being found. The fix was to load the library at the top of main instead of in the TclTest static section.
    7. I compiled the tcljava interface with:
      cd c:\tcljava0.4a
      nmake -f all
    8. To run the tcljava interface, I had to set the TCL_LIBRARY and TK_LIBRARY environment variables. Under NT, I brought up the control panel, selected the System Icon and then the Environment Tab.
      I set TK_LIBRARY to c:/Program Files/Itcl2.2/Lib/Itcl/Tk4.2
    9. The command to actually run the interface is
      java TclTest

    Troubleshooting tcljava under NT

  • You might find the Tcl/Tk on Windows FAQ useful.
  • If you get an error message that looks likes:
    The instruction at "0x1000f36b" referenced memory at "0x00000000". The
    memory could not be "read".
    The search for all the Tcl76 dlls and remove all of them except the one that you built. Also, check to be sure that you compiled Tcl and Tk with debugging turned on. Itcl2.2/tcl7.6/ and
    I fixed a bug in, where a path was hardwired in so that if the user hit the demo button, then they would see the above error. Try using a button other than demo.
  • If you get an error about not being able to find tk.tcl:
    bash$ java TclTest
    java.lang.UnknownError: Can't find a usable tk.tcl in the following directories:
       {c:/Program Files/Itcl2.2/Lib/Itcl/Tk4.2/tk.tcl} . c:/tk4.2 ./lib/itcl/tk4.2
     c:/tk4.2/library c:/library
    This probably means that Tk wasn't installed properly.
            at tcl.TkApplication.tkInit(
            at TclTest.main(
    Try setting TK_LIBRARY and TCL_LIBRARYin the system control panel under the Environment choice.
    I set TK_LIBRARY to c:/Program Files/Itcl2.2/Lib/Itcl/Tk4.2
    I set TCL_LIBRARY to c:/Program Files/Itcl2.2/Lib/Itcl/Tcl7.6