简体   繁体   中英

connect between java and swi prolog

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 am trying to run a program (it is a sample of jpl so it should work..) I am getting 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?

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)

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM