Java Exception when invoking JPL

I’m using: Lubuntu 14.04, SWI-Prolog version 8.0.3, and the JPL version says it is 7.4.0.alpha

I am trying to invoke JPL from JAVA, using the following code fragment:

	System.out.print(JPL.version_string());

	System.out.print(JPL.getActualInitArgs());

The first line is executed properly, the second one results in this error message:

Exception in thread “main” java.lang.UnsatisfiedLinkError: no jpl in java.library.path

While it seems quite logical that this call fails, assuming that without a query invocation not even an implicit init has taken place, I am nevertheless wondering how this error comes up, the more since the library has obviously been found. Or is it another library (and if so, .jar or .so) that is not found here?

On Unix systems you need to make sure that the directory holding the Java shared objects is in LD_LIBRARY_PATH (Linux; variable name depends on the OS). Add this variable, locate libjpl.so in the installed Prolog system and run

ldd libjpl.so

and check that it resolves the Java shared objects. It is not a problem if ldd cannot find libswipl.so as that will work fine when you load jpl from Prolog.

Thanks for the quick answer. I have added the path both to /etc/ld.so.conf.d and to .bashrc as LD_LIBRARY_PATH. I have checked that libjpl.so is exactly there, and I have used ldd to verify (at least it looks like that) that everything is resolved. Here is the result:

mammuth@zoo:~$ ldd /usr/lib/swi-prolog/lib/x86_64-linux/libjpl.so
linux-vdso.so.1 => (0x00007fff82773000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f636e9dc000)
libjvm.so => /usr/lib/jvm/default-java/jre/lib/amd64/server/libjvm.so (0x00007f636da8c000)
libswipl.so.8 => /usr/lib/swi-prolog/lib/x86_64-linux/libswipl.so.8 (0x00007f636d729000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f636d35f000)
/lib64/ld-linux-x86-64.so.2 (0x00007f636ee09000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f636cfdd000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f636ccd4000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f636cad0000)
libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f636c8a7000)
libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f636c627000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f636c40d000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f636c205000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f636bfef000)

Yet, the java exception persists, and it explicitly says " no jpl in java.library.path. From my previous research I understand that “jpl” is the actual name of the library not found. So somehow it is looking for a “jpl.so” or alike, if I interprete it correctly.

I have tried a call to “init()”, and it is really there that the exception occurs.

Is there some file called “jpl.so” or similar required in the lib path?

Looks all fine. Only, either editing /etc/ld.so.conf.d or .bashrc should suffice. After editing /etc/ld.so.conf.d you need to run ldconfig. Of course, after editing .bashrc you should source it or start a new shell. Seems you know enough to avoid these pitfalls :slight_smile:

Next step for me would be running under strace, e.g. strace -o jpl.log swipl, try load jpl and examine jpl.log to see which jpl/java related files it tries to find where.

I think I understand the intention of your answer. I was starting the java program from the eclipse (photon) IDE, so I guess swipl has probably never even been involved, or if, that has gone wrong. Perhaps this is the problem. I’ll try to find out. If I manage to find an answer, I’ll publish it here. Thanks so far!

First step, just start Prolog and run

?- [library(jpl)].

That is what is supposed to work. In the doc/packages/examples/jpl below the Prolog home you’ll find more examples that can be run from the shell or Prolog. Those examples should work (I hope, I only run the jpl test cases and did some packaging work on it, nothing more).

Works indeed without problem. I strongly guess that all the examples will work from prolog (but I’ll tell you if not). Why ever eclipse (or the jvm?) does not seem to find something is probably not caused on “your” side, so I think I’ll research the java/eclipse side from here on.

There are examples both ways: Prolog embedding Java and visa versa.

Already found out. :wink:

The java examples show the same problem. I simply have to find out why.

Problem solved!

Failure cause: The library needed to be specified for the JVM either in the PATH variable or in java.library.path. I don’t know exactly how to manipulate the latter for JDK, but for Eclipse (Photon), I have achieved it as follows:

(Project) Properties (from the project menu or by right click on the project)
=> Java Build Path
=> choose Libraries
=> see the jar in question (in this case: jpl.jar).
=> expand it by clicking the triangular button to its left.
=> select “Native library location”
=> by clicking the “edit” button to the right (all exept for this and “remove” should be greyed out) a window opens to enter the library path.
once done so, press “apply”

This way, the error has disappeared.

Alternatively, one can add it to the path in “.bashrc”