1
votes

I wanted to connect Java and Swi Prolog together using JPL. When I added the library to my project on Intellij the code compiled and when I tried to run a query I got a runtime error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jpl in java.library.path: [C:\Program Files\Java\jdk-12\bin, C:\WINDOWS\Sun\Java\bin, C:\WINDOWS\system32, C:\WINDOWS, c:\swipl\bin, ${env_var:PATH}, .]
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2660)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:827)
at java.base/java.lang.System.loadLibrary(System.java:1902)
at org.jpl7.JPL.loadNativeLibrary(JPL.java:114)
at org.jpl7.fli.Prolog.<clinit>(Prolog.java:71)
at org.jpl7.Query.open(Query.java:369)
at org.jpl7.Term.textToTerm(Term.java:155)
at org.jpl7.Query.<init>(Query.java:169)
at Main.main(Main.java:7)

I have the swi prolog 64 bit.

I've tried uninstalling it and use the 32 bit but it did not work.

What I did so far:

I added SWI_HOME_DIR to my Environment Variables. I also added the swi path to Path variable. I added the jpl library to my project (and it added it successfully).

The code I was trying to run:

import org.jpl7.*;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        Query q = new Query("true");
        q.hasSolution();

        Map<String,Term>[] res = q.allSolutions();

        for (int i = 0; i < res.length; i++) {
            System.out.println(res[i]);
        }
    }
}
1
According to the documentation: "In Windows, jpl.dll can go in any folder on your PATH; perhaps %SWI_HOME_DIR%\bin or your Windows’ system folder." --- Is the jpl.dll file there, in a folder listed on your PATH? Is it the 64-bit version? I'm not asking if the bin folder is on your path, I'm asking if that specific file can be found on the path.Andreas
Yes, and it is the 64 bit version.Danny
So if you do a dir c:\swipl\bin\jpl.dll from a command prompt, it will list the file? And you are running 64-bit Java? And you are sure the file is the 64-bit version? If yes to all, then the file might be corrupt, to try getting another copy.Andreas
I have jpl.jar not .dllDanny
Then the error message is exactly right, huh? Go figure. Next time, read the comment, because my first comment explicitly said jpl.dll. I even bolded it so you could see, but I guess you didn't.Andreas

1 Answers

1
votes

So, is jpl.dll in any of the listed directories:

C:\Program Files\Java\jdk-12\bin   ... probably not 
C:\WINDOWS\Sun\Java\bin            ... probably not
C:\WINDOWS\system32                ... probably not
C:\WINDOWS                         ... probably not
c:\swipl\bin                       ... apparently yes as c:\swipl\bin\jpl.dll exists?
${env_var:PATH}                    ... apparently not

Try the suggestion from this question in your Java program:

File nativeFile = new File(filename + ".dll");
    if (!nativeFile.exists())
        System.exit(1);

System.load(nativeFile);

Note that just having jpl.jar is not enough. One needs the jpl.dll file, too. jpl.jar is good for the Java part of the Java-Prolog bridge, but to be able to call a non-JVM compilate, we need to get into system-level details, Hence the dll file.

See troubleshooting tips here: JPL Deploying for users - on Windows

From the above page:

If the Java examples complain that

The dynamic link library libpl.dll could not be found in the specified path

or

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\paul\bin\jpl.dll: Can't find dependent libraries

then there is no SWI-Prolog library libpl.dll in any folder on your PATH: you should have a PATH entry such as C:\Program Files\pl\bin.

The libpl.dll should contain the code for SWI-Prolog itself.