Using the live development tree

Suppose you want to run the SWIPL (and JPL) system that is currently under the development source tree and not yet installed in the system. In this example, we first save the directory where SWIPL was built by CMAKE in environment variable SWI_BUILD as follows:

export SWI_BUILD=/home/ssardina/git/soft/prolog/swipl-devel.git/build/

We can now start SWIPL from CLI as follows:

$ $SWI_BUILD/src/swipl -x $SWI_BUILD/home/boot.prc -F swipl --home=$SWI_BUILD/home 
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.1-34-g9adbe8ff1-DIRTY)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

    CMake built from "/home/ssardina/git/soft/prolog/swipl-devel.git/build"

For online help and background, visit
For built-in help, use ?- help(Topic). or ?- apropos(Word).


The option -F swipl in the source tree will execute file swipl.rc which sets-up all the search paths for this particular development and uninstalled version.

Next, if we want to use JPL, we need to set-up two variables:

export CLASSPATH=$SWI_BUILD/packages/jpl/src/main/java/jpl.jar:$CLASSPATH

The setting of CLASSPATH is necessary so that has access to the JPL JAR compiled in the development tree (to access JAVA from Prolog).

The setting of LD_LIBRARY_PATH is necessary so that SWIPL can find the just compiled but uninstalled This is because the “temporary” home dir in the development source tree does not include the usual lib/ directory with the compiled native libraries: they are all under $SWI_BUILD/packages when compiled.

Finally, the use of some packages may require:


Using SWIPL & JPL embedded

When calling SWIPL & JPL from an embedded Java application (instead of just calling SWIPL from CLI), one will need to initialize the SWIPL engine from the Java code so that the SWIPL in the development source tree is used.

To do so, we can first define the environment variables as folows:

export SWIPL_BOOT_FILE=$SWI_BUILD/home/boot.prc
export CLASSPATH=$SWI_BUILD/packages/jpl/src/main/java/jpl.jar:$CLASSPATH

Using such variables, we can use the following Java code to initialize SWIPL correctly:

public static final String swi_home = System.getenv("SWI_HOME_DIR"));
public static final String swi_startup  = System.getenv("SWIPL_BOOT_FILE"));
public static final String swi_exec = String.format("%s/../src/swipl", home);

String init_swi_config =
        String.format("%s -x %s -F swipl --home=%s -f none -g true -q",
            swi_exec, swi_startup, swi_home);
JPL.setDefaultInitArgs(init_swi_config.split("\\s+"));	# initialize SWIPL engine

Again, the option -F swipl will execute file swipl.rc to sets-up all the search paths for this particular development and uninstalled version: it won’t be necessary for installed SWIPL systems (e.g., in /usr/local).

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