8.2.4 Running SICStus from Java

If Java is used as parent application, things are a little more complicated. There are a couple of things that need to be taken care of. The first is to specify the correct class path so that Java can find the Jasper classes (SICStus, SPTerm, and so on). This is done by specifying the pathname of the file jasper.jar:

     % java -classpath $SP_PATH/bin/jasper.jar ...

SP_PATH does not need to be set; it is only used here as a placeholder (see CPL Notes). See the documentation of the Java implementation for more info on how to set classpaths.

The second is to specify where Java should find the Jasper native library (libspnative.so or spnative.dll), which the SICStus class loads into the JVM by invoking the method System.loadLibrary("spnative"). Under UNIX, Jasper can usually figure this out by itself, but in the event that Jasper is used in a non-standard installation, this will most likely fail. A typical example of such a failure looks like:

     % java -classpath [...]/jasper.jar se.sics.jasper.SICStus
     Trying to load SICStus.
     Exception in thread "main" java.lang.UnsatisfiedLinkError: no spnative
     in java.library.path
     	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1133)
     	at java.lang.Runtime.loadLibrary0(Runtime.java:470)
     	at java.lang.System.loadLibrary(System.java:745)
     	at se.sics.jasper.SICStus.loadNativeCode(SICStus.java:37)
     	at se.sics.jasper.SICStus.initSICStus(SICStus.java:80)
     	at se.sics.jasper.SICStus.<init>(SICStus.java:111)
     	at se.sics.jasper.SICStus.main(SICStus.java:25)

Under UNIX, this can be fixed by explicitly setting the Java property java.library.path to the location of libspnative.so, like this:

     % java -Djava.library.path=/usr/local/sicstus4.3.0/lib [...]

Under Windows, Java must be able to find spnative.dll through the PATH environment variable (see Windows). Setting -Djava.library.path under Windows can lead to problems if multiple versions of SICStus have been installed.

If this works properly, SICStus should have been loaded into the JVM address space.

If everything is set up correctly, you should be able to call main (which contains a short piece of test-code) in the SICStus root class, something like this:

     % java -Djava.library.path="/usr/local/sicstus4.3.0/lib" \
            -classpath "/usr/local/sicstus4.3.0/lib/sicstus-4.3.0/bin/jasper.jar" \
             se.sics.jasper.SICStus
     Trying to load SICStus.
     If you see this message, you have successfully
     initialized the SICStus Prolog engine.

Under Windows, it would look something like this, depending on the shell used:

     % java -classpath "C:/Program Files/SICStus Prolog 4.3.0/bin/jasper.jar" se.sics.jasper.SICStus
     Trying to load SICStus.
     If you see this message, you have successfully
     initialized the SICStus Prolog engine.

If more than one se.sics.jasper.SICStus instance will be created, the SICStus runtimes named e.g. sprt4-3-0_instance_01_.dll need to be available as well. See Runtime Systems on Target Machines.


Send feedback on this subject.