Version 4 of tclJBlend

Updated 2016-08-11 15:47:38 by ABU


tclJBlend 2.0a1 (alpha release)

ABU 11-aug-2016

tclJBlend (aka "Tcl-J-Blend" or "TJB") is a new fork of TclBlend (See ), a Tcl extension that uses JNI to communicate with a Java interpreter.

Why a fork ?

The main goal of TJB is to provide the same TclBlend command interface, with a single 'binary' package that can be installed and run on all the most popular platforms (Windows,Linux,MacOS), independently of the JVM installed on the target computer.

This means that - with no need of rebuild - you can install/copy TJB on Win/Linux/Mac, and moreover, once installed, you are also free to change/upgrade the underlyng Tcl or JVM - again, with no need to rebuild TJB .

To achieve this goal TJB lost the TclBlend/Tcljava ability to act as a bidirectional bridge between a JVM and a Tcl interpreter; TJB can be used only in one way, from Tcl to Java and not in the opposite direction. For many Tcl users like me, this is enough.

Changing the true nature of TclBlend/Tcljava, required radical changes on the original TclBlend code, not to mention the completeley redesigned build procedures; hence the need of a fork: TclJBlend .

TJB main features

  • TJB provides the same TclBlend command interface (See the "Tcl/Java Package Commands" )
  • TJB is delivered as a single, multi-platform package, ready to run on all the most popular platforms: Windows (32/64 bit), Linux (32/64 bit) and MacOsX.
  • You can run TJB from any Tcl interpreter : "tclsh", "Wish" or even "tclkit" (See Note:1)
  • TJB does not depend on a specific version of the installed Java runtime (JVM). (See Note:2)


  • Note:1) TJB runs with Tcl 8.5.X and 8.6.X (and further ..) , *excluding* Tcl versions from 8.6.1 to 8.6.5 ( see Ticket )
    Tcl 8.6.1 introduced a small change stopping extensions like tclblend. Tcl 8.6.6 re-enabled the support for such extensions
  • Note:2) JVM should be >= 1.4. (Currently only SUN/Oracle JVMs have been tested).


  • TJB 2.0a1 ...
  • TJB Development-Kit ...

How to use TJB

What you need:

  • A Tcl interpreter, of course:
    • tclsh or wish, or even tclkit
  • A JVM:
    • just a JRE, a JDK is not required.
      It's not required JRE be 'installed' i.e. you don't need java.exe be in PATH, nor other special variable such as JAVA_HOME need to be set (nor the JRE need to be registered in the Windows Registry').
      Please take not of the directory containing the entry point of the JVM: "jmv.dll" ( or its equivalent "" (Linux) or "libjvm.dylib" (MacOs) ).

A big little WARNING: Don't mix 32/64 bit applications; Tcl and JVM should be both 32bit or both 64bit.

  • the TJB package
    • Download the last public release, unzip it and place it as a subdirectory of one of the Tcl 'lib' directories.
      Alternatively, you can leave it 'out of Tcl', provided later you tell Tcl where TJB is placed.

Once you have all these components, *before launching the Tcl interpreter*, you should add to LD_LIBRARY_PATH the directory containing "jvm.dll" ( or its equivalent "" (Linux) or "libjvm.dylib" (MacOs) ).

Now you are ready to run ..

Running on Windows

Set LD_LIBRARY_PATH (in dos-notation or even in unix-notation) and launch Tcl

   DOS> set LD_LIBRARY_PATH="c:\MYJRE\bin\client:%LD_LIBRARY_PATH%"  
   DOS> tclsh

then type the following Tcl commands

   # Uncomment and adapt the following line if TJB is not placed in a directory
   #  referenced by the auto_path variable.
   # lappend auto_path ...where-is-TJB...
   package require JBlend
    # create a Java object ( a java.lang.String ) 
   set x [java::new java.lang.String "Hello Tcl ! I'm a Java String"]
    # call the "toUpperCase" java-method
   set res [$x toUpperCase]
   puts $res

Running on Linux

Set LD_LIBRARY_PATH and launch Tcl

   sh> LD_LIBRARY_PATH=".../jre1.7.0_80/lib/amd64/server;$LD_LIBRARY_PATH"
   sh> export LD_LIBRARY_PATH
   sh> tclsh

then type the (same) Tcl commands

   # Uncomment and adapt the following line if TJB is not placed in a directory
   #  referenced by the auto_path variable.
   # lappend auto_path ...where-is-TJB...
   package require JBlend
    # create a Java Object ( a java.lang.String ) 
   set x [java::new String "Hello Tcl ! I'm a Java String"]
   set res [$x uppercase]
   puts $res

Note: it is important to set LD_LIBRARY_PATH *before* launching Tcl ; setting env(LD_LIBRARY_PATH) from inside Tcl would be easy, but it doesn't work !

The TJB workbench (only for TJB mainteners)

Download: .....

No documentation, yet. Just few quick notes:

  • You need a JDK, plus a GNU/C compiler.
  • On Windows you can download MingW , or you can use the free "MS Visual Studio 2005 Community Edition".

On windows

   cd ...\tclJBlend-devkit
   ms-build x32
   ms-build x64

On Unix (Linux/Mac or Windows+MingW)

   cd .../tclJBlend-devkit
   ./ x32
   ./ x64

NOTE: Building on MacOsX is still experimental ..