Bill Clementson's Blog

Bits and pieces (mostly Lisp-related) that I collect from the ether.

June 2004
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
May  Jul

CL to Java

Sunday, June 27, 2004

Ok, let's look at what would appear to be a fairly common occurrence for many CL programmers today: you would like to use Common Lisp but need to either use Java or deal with Java code. There can be a variety of different reasons for this including:

  1. Better Suited: Your company's standard is Java but the particular problem you need to write code for is either much easier to program in Lisp or there is already some Lisp code that you can use as a base. Ideally, you would like to write the code in Lisp but have it either translated to Java or directly compiled to Java byte code.
  2. Interoperabiltiy: You need to interoperate with other code that is written in Java. You can write your code in CL but need some mechanism to call out to the Java code.
  3. Libraries: There are specific packages that are written in Java that you would like to use (and there are no CL equivalents). This is similar to #2, but, in this case, you need to be able to use the packages and the class definitions in the packages in the same way that a Java programmer would use them.
Now, let's assume a perfect world in which there are no political issues associated with the decision ;-), only technical ones. In order to deal with the technical issues, there are a number of different approaches that can potentially be taken: I recently had a look at the different available options and came up with the following (Note: most of the descriptions are taken pretty much verbatim from their web sites). Some of these are probably mis-categorized (for example, it is questionable whether JACOL and jLinker should be in the FLI grouping or the RPC grouping); therefore, you should just consider these categorizations as broad groupings: Of these, I only have personal experience with jLinker, ABCL, SISC, Kawa, XML-RPC and SOAP.

I found jLinker to be an excellent product. Franz ships a number of jLinker demo programs with ACL that really show off jLinker's capabilities nicely. You can either call out to Java from CL or use jLinker to instantiate Java classes inside of CL and work with them much the same as you would work with CLOS objects (e.g. - you don't need a Java program to talk to, you can just utilize existing Java package libraries).

ABCL is still a work in progress but is showing a lot of promise (if you want to try it out, be sure to use the CVS code as the last official release was in 2003 and the CVS code has quite a few enhancements). ABCL handles some CL code really well but is incomplete in a number of areas. There is the beginning of support for ABCL in SLIME and the cl-bench benchmark tests are starting to include tests for ABCL as well.

Both SISC and Kawa appeared to be good Scheme-in-Java options but I have not really done any more than some superficial testing with them. Chris Double, on the other hand, has done a lot of work with SISC and Java-based web servers. Have a look through some of his weblog postings if you're interested in this approach.

I have done some XML-RPC and SOAP testing with a number of different CL packages. XML-RPC is very easy to use and (if your needs are relatively straight-forward) is a nice option for distributed computing across different language implementations. SOAP is more full-featured and complicated; however, it is where most of the corporate world is heading and is the more likely option that you will have available to you if you are writing software that must interoperate with Java code in an enterprise (Note: I recently posted about a meeting of the Denver Area Lisp User Group that discussed using SOAP with CL).

So, there are a number of different CL<->Java alternatives available now and some interesting ones on the horizon. I'd like to hear about other people's experiences, so please let me know if you've tried out some of these (or other) alternatives.

emacs Copyright © 2005 by Bill Clementson