From: Chris Double
Subject: Java Integration with Lisp using Corman Lisp
Date: 
Message-ID: <wkzo8lg1bi.fsf@double.co.nz>
A while ago I made a comment about some code for calling Java from
Corman Lisp. I was unable to find the latest version of the code (lost
during some system upgrade/crash/something a while back I think) but
dug up and older iteration from a backup.

It's really just my experimentations with JNI (Java Native Interface)
using Corman Lisp so isn't anything too useful. I've made it available
in case someone likes the idea enough to do something with it. The
example given runs the Java Swing Notepad by calling the Java methods
to make it appear, from Lisp. It's possible to call Lisp from Java as
well although my example doesn't demonstrate it.

It's available at:
  http://www.double.co.nz/cl

Discussion about it is probably best on the Corman Lisp mailing list:

  http://groups.yahoo.com/group/cormanlisp

Below is my original post to that list. I repost here because some
here asked me for further information when I first mentioned it.

-------------------8<-------------------

Further to my previous post I found some of my old JNI routines
ferretted away. Unfortunately it doesn't seem to be the latest version
so I'll keep digging. In case I don't find the later version I've put
what I've got up for download. It's at:

  http://www.double.co.nz/cl

There's a link to a jni10.zip there. Downloading and unzipping gives a
jni.lisp. Before loading into Corman Lisp (tested with V1.5) change
the constants +jvm-dll+ and +jdk-path+ to point to the locations of
the JVM DLL being used and the path to the JDK (for the example). 

After making the above changes, load the file. At the very bottom of
the file you should see a section with ';;Start here'. Evaluate the
'doit' function definition. Then run the create-thread call. Voila,
hopefully a Java Swing notepad window will appear. Give it a few
seconds. The initial loading is slow...it's Java afterall ;-)

Some quick caveats.

1) Exiting the notepad shuts down Corman Lisp. This is because the
   'Exit' call used by the notepad calls some process shutdown method
   which closes the entire process. It is possible to redefine or hide
   the java exit call such that this does not happen. I forget how to
   do it though (something to do with defining security IIRC). The
   same way that applets are prevented from calling it.

2) Further up in the file are some other examples of calling Java
   methods. Lots of things can be done and this file is really just a
   workspace of my experimentation in that area at the time, about 1
   or 2 years ago.

3) For JNI documentation see:
   http://java.sun.com/j2se/1.4/docs/guide/jni/index.html

4) It would be *really* cool to tidy this up and allow calling Java
   routines from Lisp and Lisp from Java. I went some ways towards
   this in a later iteration but the code seems to have gone
   walkabout.

5) I tested just now with JDK 1.3 and Corman Lisp 1.5. Works fine.

Hope it proves useful to someone. Feel free to take it and make it
useful. I probably won't be doing anything to it for some time to come
so don't feel you have to wait for me!

Comments and suggestions are most welcome.
--------------------8<-------------------

Regards,
Chris.
-- 
http://www.double.co.nz/cl