4

I am trying to run swi prolog from java.

I am using eclipse and I have inserted jpl.jar into the project (properties->libraries->add external jar) and when I try to run a program (it is a sample of jpl so it should work..) I get an error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jpl in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1758)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1045)
    at jpl.JPL.loadNativeLibrary(JPL.java:100)
    at jpl.fli.Prolog.<clinit>(Prolog.java:85)
    at jpl.Query.open(Query.java:286)
    at jpl.Util.textToTerm(Util.java:162)
    at jpl.Query.<init>(Query.java:198)
    at faf.Main.main(Main.java:10) <br>

What am I missing?

Chenmunka
  • 685
  • 4
  • 21
  • 25
Noray
  • 165
  • 2
  • 6

4 Answers4

2

I had this problem today on Debian, and my solution was similar to Felix Dobslaw's. Because I couldn't find it elsewhere, I'll post how I solved it today.

My SWI-Prolog and JPL were installed via apt-get. Change the path folders accordinly to your environment.

  • Copy libswipl.so from /usr/lib to usr/lib/swi-prolog/lib/amd64

    (sudo cp <probably-user-lib>/libswipl.so <installation-folder-swi>/lib/<architeture>)

  • Add -Djava.library.path="/usr/lib/swi-prolog/lib/amd64" as VM Option

    (Project Properties -> Run -> VM Options)

Community
  • 1
  • 1
villasv
  • 6,304
  • 2
  • 44
  • 78
1

There should be a jpl dll or so, depending on your platform. You should either make it accessible somewhere in %PATH% or specify its location with -Djava.library.path=<path to jpl.dll> java property.

Read more about JPL installation

Denis Tulskiy
  • 19,012
  • 6
  • 50
  • 68
1

I had the same problem. This helped me on Ubuntu:

1) Point the native library location of the jpl jar to the folder where you hold your "libswipl.so" (I do that via the "Java Build Path" settings of the project). For me that is:

/usr/lib/swipl-6.2.6/lib/x86_64-linux

2) Add the folder where you hold your "libjava.so" to your LD_LIBRARY_PATH variable (I do that in my run configuration under the Environment tab). For me that is:

/usr/lib/jvm/java-6-openjdk/jre/lib/amd64

Felix Dobslaw
  • 383
  • 4
  • 13
0

Solution for Eclipse Neon and homebrew:

brew update
brew install swi-prolog --with-jpl

In your Eclipse Run/Debug-Configuration set as VM-Arg:

-Djava.library.path=/usr/local/Cellar/swi-prolog/7.4.2/libexec/lib/swipl-7.4.2/lib/x86_64-darwin16.6.0

Actual path may vary.

d135-1r43
  • 2,485
  • 1
  • 25
  • 33