Pergunta

Does anyone know how (or if) you can use ABCL to compile Lisp code to .class files and create a main method so that the whole thing could be packaged into a .jar file and run?

Also, does anyone know how to access primitives Java types from ABCL code?

Foi útil?

Solução

Didier Verner posted his experiences with just such a packaging question the other day.

Outras dicas

If one is looking for more packaging around a solution, ABCL has the ability to load ASDF definitions from an URI that the class loader understands. The ASDF-INSTALL is loaded by this mechanism (use the Ant build target 'abcl.contrib'), but as a simple example, the following code will dynamically load a trivial test of ASDF loading via URI.

CL-USER> (pushnew #p"jar:http://abcl-dynamic-install.googlecode.com/files/asdf-uri-test.jar!/asdf-uri-test/" asdf:*central-registry*)
(#P"jar:http://abcl-dynamic-install.googlecode.com/files/asdf-uri-test.jar!/asdf-uri-test/" #P"jar:file:/Users/evenson/work/abcl/dist/abcl-contrib.jar!/asdf-install/" (MERGE-PATHNAMES ".asdf-install-dir/systems/" (USER-HOMEDIR-PATHNAME)) (MERGE-PATHNAMES "work/lsw/" (USER-HOMEDIR-PATHNAME)))
CL-USER> (asdf:load-system :test)
; Loading system definition from jar:http://abcl-dynamic-install.googlecode.com/files/asdf-uri-test.jar!/asdf-uri-test/test.asd into #<PACKAGE "ASDF0">
; Registering #<SYSTEM :TEST> as TEST
; Compiling jar:http://abcl-dynamic-install.googlecode.com/files/asdf-uri-test.jar!/asdf-uri-test/test.lisp ...
; (DEFUN TEST ...)
; Wrote /Users/evenson/.cache/common-lisp/abcl-0.25.0-dev-fasl37-macosx-java/files/asdf-uri-test.jar/asdf-uri-test/ASDF-TMP-test.abcl (0.163 seconds)
T
CL-USER> (test)
"The test function loaded!"

You can study that jar for packaging, but basically it just involves creating an ASDF definition, then simply packaging it as a JAR. Note that the JAR just contains Lisp source which is automatically compiled via the ASDF2 implementation to a local directory via the OUTPUT-TRANSLATION-LOCATION mechanism. Any Java class files in the JAR are currently ignored. Although Java class files should be "platform independent", there are enough JVM implementations out there (qv. Java 5 v Java 6) that it makes sense to compile the Lisp per ABCL implementation. There is certainly the ability to load an ABCL FASL via URI as well so the current ASDF implementation could probably be modified if someone has a use case for never compiling on initial ASDF load.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top