As much as I dislike Java, it's indisputable that there are lots of available libraries, and using them from Smalltalk would be convenient. Well - Joachim Geidel has been working to make that possible from Cincom Smalltalk. I found this in the VWNC mailing list:
I have posted an updated version (0.29) of JNIPort for VisualWorks to the Cincom Public Repository.
JNIPort is an interface which makes it possible to transparently use
Java libraries from Smalltalk. It invokes a Java VM using the Invocation
Interface functions of the Java Native Interface (JNI). It can
automatically generate wrapper classes for Java classes, enabling you to
write code like this:
| jvmSettings jvm zfClass zipfile entries |
jvmSettings := (JVMSettings new)
name: 'JVM with ghost class generation';
yourself.
jvmSettings usesGhosts: true.
jvmSettings jniPortSettings useJNIHelperLibrary: true.
jvm := JVM newWithSettings: jvmSettings.
zfClass := jvm findClass: #'java.util.zip.ZipFile'.
zipfile := zfClass new_String: 'MyZipFile.zip'.
zipfile size_null. "--> answers an Integer"
entries := zipfile entries_null.
entries asAnEnumeration
do: [:each | Transcript cr; print: each].
The methods new_String:, size_null, entries_null will be generated in a
"ghost class" when the JVM accesses the Java class - no need to write
code! (But be prepared to wait some seconds for ghost class generation
during JVM creation.)
Most of the unit tests are green, but there are still some bugs:
- There are some tests which fail because using out-of-range values for
short and byte values does not raise exceptions as expected.
- One test fails because of a bug somewhere in the conversion between
Java and Smalltalk strings (only for two-byte characters).
- When using a JVM with ghost class generation, accessing the result of
methods answering single characters is broken (methods answer a
Character, but try to use it as an Integer).
- Callbacks from Java do not work yet, they raise an Exception because
the Java side does not find the callback methods.
- Using "lazy ghost classes" to avoid the long setup phase when starting
a JVM using ghost classes does not work yet.
What's next (feel free to help me):
- Fix the bug in String conversion.
- Fix the bug of trying to interpret Character results as Integers
for JNI methods answering jchars.
- Add checks for out-of-bounds values for short and byte values.
- Make callbacks work.
- Add a GUI for configuration, monitoring, and inspecting ghost classes.
- See what happens when using Java 1.6.
Joachim Geidel
This is a cool project, and it looks like we'll be including a snapshot of the code on the CD in "contributed".
Technorati Tags:
java, interop