CL+J

A Common Lisp Interface to Java.



Introduction

CL+J is a JNI based interface to a Java Virtual Machine through CFFI. It targets safe, exact and complete access to Java from Common Lisp with as high integration as possible of the Java and CL respective runtime environments (especially at the condition/exception level).

CL+J uses a set of reader dispatch-macros to simplify the Java code interface. In CL+J the traditional "Hello World!" becomes:

(#_System.out.println (jstr "Hello World!"))

Printing the list of System properties to the Java standard output stream is simply:

(#_list (#_System.getProperties) #?System.out)

Download

The current version of CL+J is 0.4.

You can download it from here: cl+j-0.4.tar.gz

Implementation support

CL+J 0.4 works fully on MKCL on any platforms supported by MKCL (Linux/x86 (32bits), Linux/x86_64 (64 bits), Windows XP (Win32) or later, Windows 7 (Win64) or later) with either Java 6, 7 or 8.

Further CL implementations will be tested in turns subsequently.

Implementation support (for previous releases)

Co-existence with such an elaborate set of foreign code as a full Java Virtual Machine certainly is, constitutes pretty much the ultimate acid test for a Common Lisp Foreign Function Interface subsystem. Only a few Common Lisp environments can meet such a challenge. Here is a non-exhaustive list of CL systems known to work with CL+J 0.3, in decreasing order of reliability:



Library Requirements



Getting Started

You need to specify the location of your JRE like this:

(defvar cl-user:*jre-home* "/some/path/leading/to/your/jre")

or tell the exact location of your JVM shared library like this (would end in jvm.dll on MS-Windows):

(defvar cl-user:*jvm-path* "/some/path/to/your/libjvm.so")

You should also provide some options to be read at JVM creation time with something like this:

(defvar cl-user:*jvm-options* '("-Djava.class.path=/your/path/to/cl_j.jar:/and/maybe/some/other.jar"))

or, if you need more options to be passed during initialization of the JVM:

(defvar cl-user:*jvm-options* '("-Djava.class.path=/your/path/to/cl_j.jar:/and/maybe/some/other.jar" "-Xrs"))

Now that the context is set, you can ask ASDF to compile and load CL+J this way:

(asdf:oos 'asdf:load-op :cl+j)

You are then ready to initialize the Java VM by calling:

(cl+j:java-init)

At this point Java is fully accessible.



Documentation

Proper documentation of the CL+J public interface has yet to be written. In the meantime you could have a look at the code in the demos directory.

Currently the small programs in the demos directory should be loaded from a package that uses package "CL+J" like this:

CL-USER> (cl+j:java-init)

CL-USER> (use-package :cl+j)

CL-USER> (load "demos/hello_swing.lisp")

TODO

Mailing Lists



News

2017-01-08: CL+J 0.4 released

2012-07-22: CL+J 0.3 released.

2011-06-01: CL+J 0.2 released.

2009-03-19: CL+J 0.1 released.