2

I want to use JPL to create a graphic interface to my project, so I went and searched a code example to start working with, I downloaded the code but when I run it, it shows the following message:

ERROR: c:/program files/swipl/library/jpl.pl:4243:
        '$open_shared_object'/3: Não foi possível encontrar o módulo especificado (this stands for "it wasn't possible to find the especified module)".

ERROR: c:/program files/swipl/library/jpl.pl:4243:
        c:/program files/swipl/library/jpl.pl:4243: Initialization goal raised exception:
        library `java' does not exist (Please add directory holding java.dll to %PATH%)
ERROR: c:/users/User/desktop/system/medical expert system.pl:4:
        Exported procedure jpl:jpl_c_lib_version/1 is not defined

And when I try to use one function of the code it shows:

ERROR: Undefined procedure: jpl:jni_func/3
ERROR: In:
ERROR:   [14] jpl:jni_func(6,'javax/swing/JFrame',_10490)
ERROR:   [13] jpl:jFindClass('javax/swing/JFrame',_10522) at c:/program files/swipl/library/jpl.pl:1631
ERROR:   [12] jpl:jpl_type_to_class(class([javax|...],['JFrame']),_10554) at c:/program files/swipl/library/jpl.pl:3049
ERROR:   [11] jpl:jpl_new_1(class([javax|...],['JFrame']),['Expert System'],_10606) at c:/program files/swipl/library/jpl.pl:169
ERROR:   [10] jpl:jpl_new('javax.swing.JFrame',['Expert System'],_10664) at c:/program files/swipl/library/jpl.pl:138
ERROR:    [9] interface2 at c:/users/User/desktop/system/medical expert system.pl:180
ERROR:    [7] <user>
ERROR: 
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.

I kinda tried to put the folder containing java.dll to the PATH in System Variables but it keeps showing the same message My SWI-Prolog is version 7.6.4 64 bits, I don't think there's nothing wrong with the code itself because there's no one complaining about it in the video I downloaded it from.

Edit: the message saying that java.dll is now gone and now there's only the 2 other messages remaining, and I've already included everything I thought it was relevant in the Path under System Variables.

  • 1
    Of interest: SWI-Prolog FAQ [JPL](http://www.swi-prolog.org/FAQ/Java.html) - Short paragraph about JPL. – Guy Coder Feb 06 '19 at 17:45
  • Of interest: JPL: A bidirectional Prolog/Java interface [Web Page](http://www.swi-prolog.org/packages/jpl/) - Includes links to Objectives, Using Prolog from Java, User Guide, API reference, Gotchas, installation, release notes, – Guy Coder Feb 06 '19 at 17:45
  • 1
    Of interest: SWI-Prolog documentation: [JPL](http://www.swi-prolog.org/pldoc/man?section=jpl) - List the predicates for use with JPL. – Guy Coder Feb 06 '19 at 17:46
  • Related question: [An easy to implement prolog graphical interface](https://stackoverflow.com/questions/54445286/an-easy-to-implement-prolog-graphical-interface) – Guy Coder Feb 06 '19 at 17:49
  • uninstalling and Installing new version solved my problem but make sure you download Development release from https://www.swi-prolog.org/Download.html – mklarsun Aug 21 '20 at 12:53

1 Answers1

1

Make sure that the CLASSPATH variable in System Variables includes the path to the jpl.jar file that is bundled with SWI-Prolog. As in example, in my Windows 7 VM, I get from within SWI-Prolog:

?- getenv('CLASSPATH', P).
P = 'c:/program files/swipl/lib/jpl.jar'.

All of my code that uses JPL runs fine in this variable definition. In addition, loading the JPL library should print something like (assuming a recent SWI-Prolog version):

?- use_module(library(jpl)).
% Extended DLL search path with
%   'c:/Program Files/Java/jre1.8.0_201/bin/server'
%   'c:/Program Files/Java/jre1.8.0_201/bin'

Update

Experiment with also defining the JAVA_HOME variable in System Variables. I'm on macOS where I use:

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home

The path would differ on Windows and depending on the Java version you have installed but should end with HOME.

Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
  • I did what you said, and included java.dll and jvm.dll in Path as well (it was asking me too), so now the middle message (the ones that say java.dll is not in Path) is gone, but the other 2 Error messages are still there – Lucas Alves Feb 07 '19 at 18:15
  • @LucasAlves Does the `getenv/1` goal returns a valid `CLASSPATH`? Note that the exact path may depend on your actual SWI-Prolog installation. – Paulo Moura Feb 07 '19 at 18:30
  • yes it does. I just figured something out, if I use something like jpl_primitive_type/1, it works, but the functions especified above(in the question) don't. – Lucas Alves Feb 07 '19 at 19:06
  • Does the errors also occur with the `use_module(library(jpl))` goal? – Paulo Moura Feb 07 '19 at 19:22
  • Yes, I made a file containing only the use_module(library(jpl)) goal and it shows the same 2 errors: '$open_shared_object'/3 and Exported procedure jpl:jpl_c_lib_version/1 is not defined, which are the same from the other code. – Lucas Alves Feb 07 '19 at 19:47
  • I assume you're using the goal in the file as a directive? I.e. you have a line with `:- use_module(library(jpl)).` – Paulo Moura Feb 07 '19 at 20:04
  • yes. (something I noticed, apparently, there's not a definition of jni_func/3 in my jpl.pl file, only calls to it, is it wrong?) – Lucas Alves Feb 07 '19 at 20:13
  • No. That predicate is a foreign predicate. The foreign library that defines it is loaded when you load `library(jpl)`. If that load fails for some reason, you get the errors you're observing. – Paulo Moura Feb 07 '19 at 20:23
  • I found out that if I use something like jpl:java_home(X), it returns false, when it should return my java folder. Any ideas? – Lucas Alves Feb 07 '19 at 20:47
  • Updated my answer. – Paulo Moura Feb 07 '19 at 20:53
  • Sorry it took me this long to reply, but it seems doing the JAVA_HOME thing didn't work, prolog shows the java_home folder right but it keeps showing the same errors. – Lucas Alves Feb 11 '19 at 16:27
  • So, I used trace in use_module(library(jpl)) and these shows up right before the errors: "Fail: (44) system:'$open_shared_object'/3=prolog_stack(_2748) ? creep Fail: (43) prolog_stack:is_stack(system:'$open_shared_object'/3, _2764) ? creep" and this one is right before the second error: "Exit: (30) call(system:'$close_source'(close((000001B1CA0F62E0), 'c:/program files/swipl/library/jpl.pl', (000001B1CA0EC990)), true)) ? creep" – Lucas Alves Feb 11 '19 at 20:00