Compiling error Java "package jpl does not exist" on Ubuntu

1k views Asked by At

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.

1

There are 1 answers

1
Volodymyr Gubarkov On BEST ANSWER

@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