PackageDescription: JNIPort(Bundle)
JNI PortLast published: January 6, 2011 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
http://jniport.wikispaces.com/
The documentation is work in progress. You can monitor updates by subscribing to the RSS feed at
http://jniport.wikispaces.com/space/xmla?v=rss_2_0
To use JNIPort, you also need the following components:
- "JNIPort VW75 Extensions" (only in in VisualWorks 7.5 or earlier),
- "JNIPort VW76 Extensions" (only in in VisualWorks 7.6),
- "JNIPort Prerequisites",
- "Registry" (version 28 or later),
- "FastCMethodPointers" (version 1.1 or later),
- "WeakCollections" (version 5 or later).
Tests for JNIPort are available in "JNIPort Tests", and development tools in "JNIPort Tools".
These components are available as parcels in the "Contributed" directory of the VisualWorks distribution, starting with VisualWorks 7.7. 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:
JNIPort_Extras.zip This archive contains the following files:
DolphinJNIHelper.dll and its source code
This library is needed for handling the hook functions provided by JNI for monitoring the state of a running JVM. See the package comment of ''CU JNI Helper''.
Currently only available for MS Windows.
JNIPort.jar and its source code in JNIPort.zip
This Java library is necessary for handling callbacks from Java to Smalltalk.
JNIPort-Tests.jar and its source code in JNIPort-Tests.zip
This Java library contains classes which are needed for running the tests in the bundle ''JNIPort Tests''.
JNIPort_Docs.zip This archive contains the original JNIPort documentation written by Chris Uppal. Please read this before using JNIPort.
Both files are taken from the Dolphin Smalltalk version of 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';
yourself.
jvmSettings usesGhosts: true.
jvmSettings jniPortSettings useJNIHelperLibrary: false.
jvm := JNIPort.JVM newWithSettings: jvmSettings.
zfClass := jvm findClass: #'java.util.zip.ZipFile'.
zipfile := zfClass new_String: 'JNIPort.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".