When a LispWorks application is delivered as a dynamic library which is loaded by Java, the initialization function (first argument to deliver) should initialize the Java interface. But it is also possible to initialize the Java interface later, as long as the code does not try to use Java before doing the initialization.
It is not a good idea to export
JNI_OnLoad (which is called automatically when Java loads a shared object), because it means the call to it will have to wait until LispWorks finishes initialization and is ready to accept callables, which will hang the caller until LispWorks finished initialization. On Unix you can add a piece of foreign code using the deliver keyword
:dll-added-files which exports
JNI_OnLoad that stores things only in C, maybe storing something that LispWorks can access later. It is probably a good idea to call InitLispWorks in this definition with timeout 0, so that LispWorks starts initializing in the background. Another option is to start another thread (using
pthread_create) which calls into Lisp to do the initialization.
LispWorks User Guide and Reference Manual - 13 Feb 2015