PackageDescription: JNIPort(Bundle)

JNI Port

Last published: May 3, 2015 by 'JoachimGeidel'

This bundle contains an interface to the Java Virtual Machine. It is based in the Java Native Interface (JNI). The original implementation was done by Chris Uppal in Dolphin Smalltalk. The bundle contains a port of this implementation to VisualWorks. Documentation is online at
The documentation is work in progress.

To use JNIPort, you also need the following components:
- "JNIPort Prerequisites",
- "Registry" (version 28 or later),
- "FastCMethodPointers" (version 1.1 or later),
- "WeakCollections" (version 5 or later).
Tests for JNIPort are available in the bundle "JNIPort Tests", and development tools in "JNIPort Tools".

These components are available as parcels in the "Contributed" directory of the VisualWorks distribution. Alternatively, you can load them from the Cincom Public Repository.

If you load JNIPort from a Store repository, you should configure the Store > Prerequisites settings in the VisualWorks Settings tool such that Store always loads the latest versions with blessing level "Development", and to search bundles and packages first. Some of the prerequisites are distributed with VisualWorks as parcels, e.g. the Registry parcel in the Contributed directory of the VisualWorks distribution. If you want to load these parcels instead of packages from a Store repository, set the search policy for prerequisites of type #any to "Search parcels first" in the Store > Prerequisites settings.

The bundle JNIPort contains two archives with additional files: This archive contains the following files:
JNIPort30.jar and its source code in src/JNIPort
This Java library is necessary for handling callbacks from Java to Smalltalk.
JNIPort30-Tests.jar and its source code in src/JNIPort/test and src/JNIPort/examples
This Java library contains classes which are needed for running the tests in the bundle ''JNIPort Tests''. This archive contains the original JNIPort documentation written by Chris Uppal. Please read this before using JNIPort.

Example for using JNIPort with automatic generation of wrapper classes and methods for Java classes (when evaluating the code, ignore warnings about undefined selectors):
| jvmSettings jvm zfClass zipfile entries |

jvmSettings := (JNIPort.JVMSettings new)
name: 'JVM with ghost class generation';
jvm := JNIPort.JVM newWithSettings: jvmSettings.
zfClass := jvm findClass: #''.
zipfile := zfClass new_String: 'JNIPort30.jar'.
zipfile size. "--> answers an Integer"

entries := zipfile entries.
entries asAnEnumeration do: [:each | Transcript cr; print: each].
You can start only one Java virtual machine per operating system process. This means that once a JVM has been initialized, you have to leave it running until it is no longer needed. You can always access it by evaluating the expression "JVM current".