menu
an API between SWI-Prolog and the Java Virtual Machine - hosted on GitHub

Resources and Environment Variables

As explained in Deployment, there are several resources that need to be found to run embedded applications. Different environment variables will help the application to find those resources. For the examples below, we suppose we have compiled and locally install SWIPL+JPL under /usr/local/swipl-git.

First, the variable SWI_HOME_DIR specifies the root of the SWIPL install and helps, among other things, to find the .pl libraries (under library/). It is not necessary if using the standard SWIPL install, but may be useful if using a different one, e.g.,:

export SWI_HOME_DIR=/usr/local/swipl-git/lib/swipl/

This variable is one of the ways that SWIPL will try to find/guess the resources.

Also, if one is not using the default install (e.g., the one coming with Ubuntu), one needs to set-up LD_LIBRARY_PATH to find the Native .so libraries (including libjpl.so!):

LD_LIBRARY_PATH=$SWI_HOME_DIR/lib/x86_64-linux/

For jpl.pl, the Java application, or the IDE (e.g., VSCode, IntelliJ or ECLIPSE) to have access to the right Java API, the CLASSPATH has to include the appropriate jpl.jar:

export CLASSPATH=$SWI_HOME_DIR/lib/jpl.jar:$CLASSPATH

Note also that one may need to tell your development environment or applications to use the correct jpl.jar, by correctly setting the CLASSPATH variable.

If you want to call Java from Prolog using JPL, you may need to add the directory holding the JVM shared objects to the dynamic linker search path:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/jvm/java-17-openjdk-amd64/lib/server/

Also, some applications may require the pre-loading of libraries, e.g.,:

export LD_PRELOAD=$SWI_HOME_DIR/lib/x86_64-linux/libswipl.so

Finally, and in particular for development JAVA_HOME is needed to specify which Java is been used:

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/