Feather 0.1

Alden Dima
National Institute of Standards and Technology, October 1999

Download: feather.zip (contains Windows and Solaris binaries - use the JDK's jar utility to extract - see installation notes)

What is Feather?

Feather is a public domain JavaTM package that allows a Java application to embed native Tcl interpreters within the same process as the Java virtual machine. This means that a Java program can both call Tcl scripts stored in external files and dynamically create Tcl scripts as Java strings. The result of a Tcl script is returned as a Java String.

Why Feather?

We are doing Java-based pervasive computing research and I am building a Java tool that will have to start other Java virtual machines. I found the facilities in java.lang.Runtime to be lacking the functionality that I needed. I could use native methods, but in many ways Tcl/Tk has already solved these problems in a platform-independent way. So if I could easily call Tcl scripts from a Java program, most of my problems would be easier to solve.

There are other Java-Tcl integration tools such as TclBlend and Jacl. TclBlend allows for Java-based Tcl extensions - in effect it allows a Tcl script to call Java code. Feather does things in reverse: Java code can now call Tcl scripts. The difference is that with TclBlend, Tcl is used to "script" Java, where with Feather, Tcl is used to provide services to a Java application.

Jacl implements a Tcl interpreter in Java. As a result, Tcl scripts are translated into Java bytecode that run on the Java VM. For my purposes, a problem with Jacl is that it does not implement the full Tcl command set. In addition, given that the Java facilities such as java.lang.Runtime do not meet my needs, Jacl would most likely have to be extended using native methods anyway.

What can Feather do?

In a nutshell, the nist.feather.TclInterpreter class provides two methods: eval and evalFile. The eval method takes a Java string, evaluates it as a Tcl script and returns the result as a Java string. EvalFile "sources" and external file as a Tcl script and also returns the result as a Java string. Each TclInterpreter maintains its state between method calls. For more information, look at the feather api.

With Feather, a Java program can make use of Tcl features. For example, instead of using java.lang.Runtime.exec to start another program and then fiddling with with Java to capture its standard output, a programmer can write a simple a one line Tcl script to do the same thing. This script can be stored as a Java string and then passed to the Tcl interpreter as needed. If a lot of setting up has to be done by Tcl, then a large Tcl script can be saved in a file and "sourced" by the Tcl interpreter as needed. In this way, an entire library of Tcl procedures can be made available to a Java application.

What can't Feather do?

There are a number of issues that remain to be addressed. For example, it would be nice if Feather allowed events generated by a Tcl script to call back to a Java method. It would also be useful if it could run script files found inside a jar archive. The feather native code should also be tuned - things aren't as efficient as they probably could be. Feel free to modify the included source code.

Please keep in mind that Feather is still under development and should be considered experimental software. It hasn't been extensively tested under a wide variety of conditions. Don't use it to control your nuclear reactor or run your banking system - see our legal notice.

How do I use Feather?

First create a nist.feather.TclInterpreter object:

	TclInterpreter interp = new TclInterpreter();

Then use it to evaluate Tcl scripts:

	try {
		// sourcing a tcl script
		result = interp.evalFile(new File("test.tcl"));
		// calling an individual tcl command
		result = interp.eval("set a 1");
	catch (TclEvalException e) {...}

The native Tcl interpreter is automatically destroyed when the TclInterpreter object is garbage collected.

What platforms are supported?

So far, it seems to work with the JDK 1.1 and 1.2 VMs. I've provided binaries for Win32 and Solaris Sparc. The source is also in the distribution - it should compile on other platforms without modification.

How do I install Feather?

Make sure that you have installed JDK 1.1 or higher and Tcl/Tk 8.2.

Unzip the distribution into a directory using Sun's jar utility - for example: "jar xvf feather.zip" - and then add the feather directory to the the system's CLASSPATH environment variable.

Windows users will have to add the path to feather.dll (feather\win32-ix86\Release) to the PATH environment variable while Solaris users will need to add libfeather.so's path (feather/solaris-sparc/lib) to LD_LIBRARY_PATH.

Once Feather is installed, go to the feather/nist/feather/test directory and run the test program: "java nist.feather.test.Main". Make sure that the tests complete successfully.

Related Links

By selecting the following links, you will be leaving NIST web space. We have provided these links to other web sites because they may have information that would be of interest to you. No inferences should be drawn on account of other sites being referenced, or not, from this page. There may be other web sites that are more appropriate for your purpose. NIST does not necessarily endorse the views expressed, or concur with the facts presented on these sites. Further, NIST does not endorse any commercial products that may be mentioned on these sites. Please address comments about this page to Alden Dima.

Legal Notice

Feather is released by the National Institute of Standards and Technology (NIST), an agency of the U.S. Department of Commerce, Gaithersburg MD 20899, USA. Feather bears no warranty, either express or implied. NIST does not assume legal liability nor responsibility for a User's use of Feather or the results of such use.

This software was developed at the National Institute of Standards and Technology by employees of the Federal Government in the course of their official duties. Pursuant to title 17 Section 105 of the United States Code this software is not subject to copyright protection and is in the public domain.

We would appreciate acknowledgement if the software is used.


Please direct all questions and comments to Alden Dima