-1

I installed swi-prolog by using $ sudo apt-get install swi-prolog and $ sudo apt-get install swi-prolog-java However I can't compile anything on netbeans because it gives me this:

enter image description here

As you can see on the screenshot, I even tried importing jpl.jar to the libraries of the project, yet nothing seems to work.

There are some similar questions about this but all the answers are always related to Windows , I would like to get some help regarding this package for linux users.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
Tamara
  • 3
  • 4
  • The Java portions of that package are available in `/usr/share/java`; e.g. `/usr/share/java/jpl.jar` (it looks like the native libraries are at `/usr/lib/swi-prolog/lib`), hope that helps. – Elliott Frisch Nov 11 '17 at 22:24
  • Thank you for your answer but as I stated in the question, I already added the jpl.jar to the project, the files are there where they're supposed to be. – Tamara Nov 11 '17 at 22:51

1 Answers1

0

@Tamara I looked inside jpl.jar and I guess you should use package org.jpl7 instead of just jpl.

enter image description here

Here is a piece of code that worked for me:

import org.jpl7.JPL;
import org.jpl7.Query;
import org.jpl7.Term;

public class PrologApp {
    public static void main(String[] args) {
        Query.hasSolution("use_module(library(jpl))"); // only because we call e.g. jpl_pl_syntax/1 below
        Term swi = Query.oneSolution("current_prolog_flag(version_data,Swi)").get("Swi");
        System.out.println("swipl.version = " + swi.arg(1) + "." + swi.arg(2) + "." + swi.arg(3));
        System.out.println("swipl.syntax = " + Query.oneSolution("jpl_pl_syntax(Syntax)").get("Syntax"));
        System.out.println("swipl.home = " + Query.oneSolution("current_prolog_flag(home,Home)").get("Home").name());
        System.out.println("jpl.jar = " + JPL.version_string());
        System.out.println("jpl.dll = " + org.jpl7.fli.Prolog.get_c_lib_version());
        System.out.println("jpl.pl = " + Query.oneSolution("jpl_pl_lib_version(V)").get("V").name());
    }
}

And output:

swipl.version = 7.2.3
swipl.syntax = modern
swipl.home = /usr/lib/swi-prolog
jpl.jar = 7.0.1-alpha
jpl.dll = 7.0.1-alpha
jpl.pl = 7.0.1-alpha

Check here for more examples https://github.com/SWI-Prolog/packages-jpl/tree/master/examples/java

Volodymyr Gubarkov
  • 2,173
  • 20
  • 20