Joachim  Geidel has published a preview release of JNIPort, a Smalltalk library which allows Java code to be invoked from Smalltalk. It acts as a bridge between the world of Smalltalk objects and a Java Virtual Machine (JVM) where Java code is executing.

The port to Pharo and Squeak is not yet finished: it lacks support for callbacks from Java to Smalltalk, and is a work in progress. Joachim is particularly interested in feedback from Squeak 4.1 users.

JNIPort was originally written by Chris Uppal for Dolphin Smalltalk and published under a liberal licence which permits its use in commercial and non-commercial software. Joachim Geidel originally ported JNIPort to VisualWorks in 2006 and is now building on that work to make it available to Pharo and Squeak. The goal is to publish a stable release for VisualWorks, Pharo and Squeak in Q3/2010.

In addition to giving Smalltalk programs access to Java libraries and services, the interactivity of Smalltalk makes it an ideal environment to experiment and prototype new Java functionality.

Once it’s installed, calling some Java can be as simple as three lines in your workspace:

jvm := JVM current.
class := jvm findClass: #’java.lang.System’.
class currentTimeMillis_null

Installation instructions documentation and much more information are on the JNIPort Wiki.

Torsten Bergmann has an interesting post which introduces JavaConnect, a project by Johan Brichau, a postdoctoral researcher at the Université catholique de Louvain. JavaConnect is a library (developed using Visualworks Smalltalk and released under the MIT licence) that allows a seamless interaction between Smalltalk and Java. Johan describes it as allowing a Smalltalk application to “access any Java object and send messages to it, just as if it were a Smalltalk object. Its implementation relies on a connection between the Smalltalk environment and a standard Java VM environment using Visualworks’ DLLCC and Java’s JNI. The Java application thus executes on a regular Java VM and the Smalltalk application executes on the regular Smalltalk VM.”

Joachim Geidel posted a comment giving a detailed comparison of JavaConnect to JNIPort, a similar tool developed by Chris Uppal for Dolphin Smalltalk, and ported by to VisualWorks by Joachim, a consultant for blueCarat Consulting GmbH. JNIPort (available under a bespoke, liberal licence) invokes a Java VM using the Invocation Interface functions of the Java Native Interface (JNI). It can automatically generate wrapper classes for Java classes.

Joachim and Johan developed the two projects in parallel, and have discussed whether they could merge in the future, although there are a number of differences in the designs at present. In particular, Joachim believes that JNIPort as currently implemented could be more readily ported to Squeak.