Version 7 of tclJBlend

Updated 2016-09-27 22:21:29 by ABU

tclJBlend 2.0.0a2 (alpha release)

ABU 27-sep-2016

tclJBlend (aka "Tcl-J-Blend" or "TJB") is a new fork of TclBlend (See http://tcljava.sourceforge.net/ ), 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 multiplatform 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 over 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" http://tcljava.sourceforge.net/docs/TclJava/contents.html )
  • 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 launch 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 https://core.tcl.tk/tcl/tktview?name=07d13d99b0 )
    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).

Download

  • TJB 2.0.0a2 [L1 ] Prebuilt multiplatform package
  • TJB Development-Kit [L2 ] For developers/maintainers.

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 "libjvm.so" (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 "libjvm.so" (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
   ....

Remember that Tcl and JVM should be both 32bit or both 64bit; Tcl version must be <= 8.60 or >= 8.6.6

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 java.lang.String "Hello Tcl ! I'm a Java String"]
    # call the "toUpperCase" java-method
   set res [$x toUpperCase]
   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 !

Running on MacOs

Set LD_LIBRARY_PATH and launch Tcl

   sh> LD_LIBRARY_PATH="/Library/Internet Plugins/JavaAppletPlugin.plugin/Contents/Home/lib/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 java.lang.String "Hello Tcl ! I'm a Java String"]
    # call the "toUpperCase" java-method
   set res [$x toUpperCase]
   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 the TJB Development-Kit [L3 ], or better download the last version from the SourceForge SVN repository [L4 ]

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
   ./build.sh x32
   ./build.sh x64

By default intermediate results will be saved XBUILD subdirectory; XBUILD/tclJBlend contains the deliverable package. (If you use a shared disk for building, you can attach it to Win/Linux/Mac so that XBUILD/tclJBlend will collect all the native DLL/.so/.dylib so far built).