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:



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 in the installed Prolog system and run


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

Thanks for the quick answer. I have added the path both to /etc/ and to .bashrc as LD_LIBRARY_PATH. I have checked that 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/ => (0x00007fff82773000) => /lib/x86_64-linux-gnu/ (0x00007f636e9dc000) => /usr/lib/jvm/default-java/jre/lib/amd64/server/ (0x00007f636da8c000) => /usr/lib/swi-prolog/lib/x86_64-linux/ (0x00007f636d729000) => /lib/x86_64-linux-gnu/ (0x00007f636d35f000)
/lib64/ (0x00007f636ee09000) => /usr/lib/x86_64-linux-gnu/ (0x00007f636cfdd000) => /lib/x86_64-linux-gnu/ (0x00007f636ccd4000) => /lib/x86_64-linux-gnu/ (0x00007f636cad0000) => /lib/x86_64-linux-gnu/ (0x00007f636c8a7000) => /usr/lib/x86_64-linux-gnu/ (0x00007f636c627000) => /lib/x86_64-linux-gnu/ (0x00007f636c40d000) => /lib/x86_64-linux-gnu/ (0x00007f636c205000) => /lib/x86_64-linux-gnu/ (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 “” 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 “” or similar required in the lib path?

Looks all fine. Only, either editing /etc/ or .bashrc should suffice. After editing /etc/ 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”