Discussion:
How to set-up JPL in Netbeans (or Eclipse)?
Juha Metsäkallas
2011-05-07 17:00:51 UTC
Permalink
Hello!

Platform: MS Windows Vista (32 bit).

I have downloaded and installed SWI-Prolog (version 5.11.14). It is
installed at c:\Program Files\SWI-Prolog. I have Eclipse 3.6 (Helios)
with the Prolog Development Tool (PDT) plug-in and I can run Prolog code
with it. Now I discovered the JPL so that I can make a GUI for my Prolog
code. Now, I prefer Netbeans for Java app development as I can
drag-and-drop controls with it, but Eclipse would also do. My question
is how to set-up JPL so that I can write Java code that runs Prolog?
There seems to be a lot of postings (for instance
http://www.groupsrv.com/computers/about48577.html) saying something
about classpaths here and classpaths there, but I need an *absolute
dummy's guide* for this, i.e. what menu commands, what dialogs where in
Netbeans etc.

Pointers appreciated,

Juha "Metsis" Metsäkallas
Muffin Working
2011-05-10 08:26:56 UTC
Permalink
Same here !

Embedding JPL within Eclipse isn't intuitive at all. I gave up on that and
made a .bat to compile my files, but I still use Eclipse for editing : by
adding jpl.jar as an external jar to the current jre, I can actually import
jpl.* to my classes and jpl appears in autocomplete... (which is all I ask
for writing code).
If you manage to configure it properly so that you can run your programs
inside Eclipse, please let us know... !

The Working Muffin

On Sat, May 7, 2011 at 7:00 PM, Juha Metsäkallas <
Post by Juha Metsäkallas
Hello!
Platform: MS Windows Vista (32 bit).
I have downloaded and installed SWI-Prolog (version 5.11.14). It is
installed at c:\Program Files\SWI-Prolog. I have Eclipse 3.6 (Helios)
with the Prolog Development Tool (PDT) plug-in and I can run Prolog code
with it. Now I discovered the JPL so that I can make a GUI for my Prolog
code. Now, I prefer Netbeans for Java app development as I can
drag-and-drop controls with it, but Eclipse would also do. My question
is how to set-up JPL so that I can write Java code that runs Prolog?
There seems to be a lot of postings (for instance
http://www.groupsrv.com/computers/about48577.html) saying something
about classpaths here and classpaths there, but I need an *absolute
dummy's guide* for this, i.e. what menu commands, what dialogs where in
Netbeans etc.
Pointers appreciated,
Juha "Metsis" Metsäkallas
_______________________________________________
SWI-Prolog mailing list
https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
-------------- next part --------------
HTML attachment scrubbed and removed
Paul Singleton
2011-05-10 10:09:22 UTC
Permalink
Post by Muffin Working
Same here !
Embedding JPL within Eclipse isn't intuitive at all. I gave up on that and
made a .bat to compile my files, but I still use Eclipse for editing : by
adding jpl.jar as an external jar to the current jre, I can actually import
jpl.* to my classes and jpl appears in autocomplete... (which is all I ask
for writing code).
If you manage to configure it properly so that you can run your programs
inside Eclipse, please let us know... !
JPL links Java and Prolog via C, and SWI-Prolog is a native app, so
you'll need to set PATH (or LD_LIBRARY_PATH) as well as Java's
classpath. From the Java side, the dependencies (Windows) are:

your Java code (which presumably Eclipse can find ok ;-))
needs jpl.jar (for jpl.Query etc), so add it as an external jar
which needs jpl.dll (JPL's native part), so add pl/bin to PATH
which needs swipl.dll (for SWIPL's FLI) (it too is in pl/bin)
which needs the rest of the SWI-Prolog installation.

Without a good reason to do otherwise, don't copy or move libraries
around your filestore, but link to them wherever they were installed.

If you first got the JPL examples working, you presumably already
added pl/bin to PATH? (or to LD_LIBRARY_PATH in Unix-like OSs).

swipl.dll can find SWIPL's other installed files as long as it and
they are still where the installer put them, or if SWI_HOME_DIR is
correctly defined in the inherited environment.

I've no Netbeans experience, but if you set up your global environment
to get the JPL examples working, then link jpl.jar to your project as
an external jar, it should all work there too.

AFAIK there's nothing tricksy about JPL from an Eclipse/Netbeans
perspective, apart from necessarily using native ("foreign" in Prolog
jargon) libraries.

regards - Paul S.
Post by Muffin Working
The Working Muffin
On Sat, May 7, 2011 at 7:00 PM, Juha Metsäkallas<
Post by Juha Metsäkallas
Hello!
Platform: MS Windows Vista (32 bit).
I have downloaded and installed SWI-Prolog (version 5.11.14). It is
installed at c:\Program Files\SWI-Prolog. I have Eclipse 3.6 (Helios)
with the Prolog Development Tool (PDT) plug-in and I can run Prolog code
with it. Now I discovered the JPL so that I can make a GUI for my Prolog
code. Now, I prefer Netbeans for Java app development as I can
drag-and-drop controls with it, but Eclipse would also do. My question
is how to set-up JPL so that I can write Java code that runs Prolog?
There seems to be a lot of postings (for instance
http://www.groupsrv.com/computers/about48577.html) saying something
about classpaths here and classpaths there, but I need an *absolute
dummy's guide* for this, i.e. what menu commands, what dialogs where in
Netbeans etc.
Pointers appreciated,
Juha "Metsis" Metsäkallas
_______________________________________________
SWI-Prolog mailing list
https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
-------------- next part --------------
HTML attachment scrubbed and removed
_______________________________________________
SWI-Prolog mailing list
https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
--
Paul Singleton
Jambusters Ltd

tel: 01782 750821
fax: 08707 628609
VAT: 777 3904 85
Company no. 04150146
Kilian
2011-05-10 10:38:22 UTC
Permalink
If you first got the JPL examples working, you presumably already added
pl/bin to PATH? (or to LD_LIBRARY_PATH in Unix-like OSs).
I'm on Linux, SWI-PL is installed in /home/ke/swipl, and I have set
LD_LIBRARY_PATH and SWI_HOME as follows:

export
LD_LIBRARY_PATH=/home/ke/opt/swipl/bin:/usr/lib/jvm/java-6-openjdk/jre/lib/i386:/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client:/usr/local/lib:$LD_LIBRARY_PATH
export SWI_HOME_DIR=/home/opt/swipl

Still, I get this exception, with Eclipse and without:

xception in thread "main" java.lang.UnsatisfiedLinkError: no jpl in
java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1734)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
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.Query1(Query.java:183)
at jpl.Query.<init>(Query.java:176)
at JPLTest.main(JPLTest.java:15)

When I replace /home/ke/opt/swipl/bin with
/home/ke/opt/swipl/lib/swipl-5.10.2/bin/i686-linux, with Eclipse the
behavior stays the same, but without Eclipse I get this error message
instead:

java: symbol lookup error:
/home/ke/opt/swipl/lib/swipl-5.10.2/lib/i686-linux/libjpl.so: undefined
symbol: PL_is_initialised

-Kilian
Jan Wielemaker
2011-05-10 12:00:29 UTC
Permalink
Post by Kilian
If you first got the JPL examples working, you presumably already added
pl/bin to PATH? (or to LD_LIBRARY_PATH in Unix-like OSs).
I'm on Linux, SWI-PL is installed in /home/ke/swipl, and I have set
export
LD_LIBRARY_PATH=/home/ke/opt/swipl/bin:/usr/lib/jvm/java-6-openjdk/jre/lib/i386:/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client:/usr/local/lib:$LD_LIBRARY_PATH
export SWI_HOME_DIR=/home/opt/swipl
You must be precise. SWI_HOME_DIR=/home/opt/swipl and
LD_LIBRARY_PATH=/home/ke/opt/swipl/bin cannot both be right (/ke/)

Next, the above are instructions for Windows. Windows tends to place
.ddl files and .exe files in the same dir because .exe file look in
the dir they are installed for dlls. In the Unix tradition, executables
and libraries live in different places. Typically, the shared object is
in

$SWI_HOME_DIR/lib/<arch>/libswipl.<ext>

where <arch> is the output of swipl --arch and <ext> is a platform
dependent extension (.so, .dylib, ...)

Thus, LD_LIBRARY_PATH might have to look like this.

/home/ke/opt/swipl/lib/i686-linux

This directory must include libswipl.<ext>, where <ext> is the shared
object extension for the platform (e.g., .so for Linux, .dylib for
MacOS).

There is a catch here: by default, the 32-bit Linux installation on
PC platform does not include a shared object for Prolog. This is
because shared objects are generally not needed on this platform and
they are considerably slower (about 10%). If you compile the system,
uncomment the line # EXTRACFG+=" --enable-shared" in build (copied
from build.templ).

All in all, it is a nightmare. There are good use-cases for JPL, but
quite often you are much better of if you use some form of interprocess
communication between the Java part of your app and the Prolog part.
If Prolog is not embedded you have a much better development environment
and you avoid most installation trouble.

And, this is unlikely to get better. There are just too many
combinations of Java distributions, operating systems and installation
options.

Cheers --- Jan
Kilian
2011-05-10 19:58:52 UTC
Permalink
Post by Jan Wielemaker
Thus, LD_LIBRARY_PATH might have to look like this.
/home/ke/opt/swipl/lib/i686-linux
This directory must include libswipl.<ext>, where<ext> is the shared
object extension for the platform (e.g., .so for Linux, .dylib for
MacOS).
There is a catch here: by default, the 32-bit Linux installation on
PC platform does not include a shared object for Prolog. This is
because shared objects are generally not needed on this platform and
they are considerably slower (about 10%). If you compile the system,
uncomment the line # EXTRACFG+=" --enable-shared" in build (copied
from build.templ).
Thanks, that solved the problem. It still doesn't work for me, but that
deserves its own thread after some more trying...

-Kilian
Juha Metsäkallas
2011-05-10 11:05:39 UTC
Permalink
JPL links Java and Prolog via C, and SWI-Prolog is a native app, so you'll
need to set PATH (or LD_LIBRARY_PATH) as well as Java's classpath. From the
your Java code (which presumably Eclipse can find ok ;-))
needs jpl.jar (for jpl.Query etc), so add it as an external jar
which needs jpl.dll (JPL's native part), so add pl/bin to PATH
which needs swipl.dll (for SWIPL's FLI) (it too is in pl/bin)
which needs the rest of the SWI-Prolog installation.
Without a good reason to do otherwise, don't copy or move libraries around
your filestore, but link to them wherever they were installed.
If you first got the JPL examples working, you presumably already added pl/bin
to PATH? (or to LD_LIBRARY_PATH in Unix-like OSs).
swipl.dll can find SWIPL's other installed files as long as it and they are
still where the installer put them, or if SWI_HOME_DIR is correctly defined in
the inherited environment.
<snip>


Stop! I haven't moved manually any files, and I won't do. They are where the
installer(s) put them. When I said I need an absolute dummy's guide, I meant an
_absolute_ dummy's guide. What dialog where, which checkbox needs to be checked
etc. in Eclipse (or Netbeans)? Or can't this be done in Eclipse, and I have to
go to the terminal (I'm a GUI guy who thinks terminal is sooo last millenium)?
What does setting PATH means, what to type? I can write and run Java and Prolog
on Eclipse, so they are ok by themselves, but it is the interoperabilty between
them that I don't know how to set-up.

I have now Eclipse for Java Developers (from eclipse.org) but can change to some
other if required.

TIA,

Juha "Metsis" Metsäkallas

----
Platform: MS Windows Vista 32 bit
Muffin Working
2011-05-10 13:30:53 UTC
Permalink
Post by Paul Singleton
your Java code (which presumably Eclipse can find ok ;-))
 needs jpl.jar (for jpl.Query etc), so add it as an external jar
 which needs jpl.dll (JPL's native part), so add pl/bin to PATH
 which needs swipl.dll (for SWIPL's FLI) (it too is in pl/bin)
 which needs the rest of the SWI-Prolog installation.
Without a good reason to do otherwise, don't copy or move libraries around your filestore, but link to them wherever they were installed.
If you first got the JPL examples working, you presumably already added pl/bin to PATH? (or to LD_LIBRARY_PATH in Unix-like OSs).
swipl.dll can find SWIPL's other installed files as long as it and they are still where the installer put them, or if SWI_HOME_DIR is correctly defined in the inherited environment.
I've no Netbeans experience, but if you set up your global environment to get the JPL examples working, then link jpl.jar to your project as an external jar, it should all work there too.
AFAIK there's nothing tricksy about JPL from an Eclipse/Netbeans perspective, apart from necessarily using native ("foreign" in Prolog jargon) libraries.
regards - Paul S.
Thank you Paul.

Yes, pl/bin is already in my path. And after what happened to me last
time, I didn't move and/or copy any library ;-p

Here are my environment variables (I added \pl, \pl\bin AND \pl\lib\,
just to make sure I have everything) :
Path=C:\Program
Files\Java\jdk1.6.0_24\jre\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Program
Files\Java\jdk1.6.0_24\bin;C:\Program
Files\Java\jdk1.6.0_24\lib;C:\Program
Files\Java\jdk1.6.0_24\jre\bin;C:\Program
Files\Java\jdk1.6.0_24\jre\bin\server;C:\Program
Files\Java\jdk1.6.0_24\jre\lib;C:\Program Files\pl\bin;C:\Program
Files\pl\lib;C:\Program Files\pl\;
CLASSPATH=.;C:\Program Files\pl\lib\jpl.jar
I didn't need SWI_HOME_DIR for the examples to run, but since you
asked, I added it to my environment.
SWI_HOME_DIR=C:\Program Files\pl\;

Inside Eclipse, as I mentionned earlier, I added JPL as an external
jar to my JRE and I can use JPL inside the editor. But whenever I hit
"run", here is what I get :
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jpl in
java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1734)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
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.Query1(Query.java:183)
at jpl.Query.<init>(Query.java:176)

Though the following code :
System.out.println("Path : " + System.getProperty("java.library.path"));
System.out.println("Classpath : " +System.getenv("CLASSPATH"));
returns this :
Path : C:\Program
Files\Java\jdk1.6.0_24\jre\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Program
Files\Java\jdk1.6.0_24\bin;C:\Program
Files\Java\jdk1.6.0_24\lib;C:\Program
Files\Java\jdk1.6.0_24\jre\bin;C:\Program
Files\Java\jdk1.6.0_24\jre\bin\server;C:\Program
Files\Java\jdk1.6.0_24\jre\lib;C:\Program Files\pl\bin;C:\Program
Files\pl\lib;C:\Program Files\pl\;
Classpath : .;C:\Program Files\pl\lib\jpl.jar

I also tried to add the environment variables mentionned above to my
run configuration using Run>Run Configurations...>Environment tab
Post by Paul Singleton
Select but it didn't change anything.
Any idea ?
Post by Paul Singleton
--
Paul Singleton
Jambusters Ltd
tel: 01782 750821
fax: 08707 628609
VAT: 777 3904 85
Company no. 04150146
Juha Metsäkallas
2011-05-20 07:43:04 UTC
Permalink
JPL links Java and Prolog via C, and SWI-Prolog is a native app, so you'll
need to set PATH (or LD_LIBRARY_PATH) as well as Java's classpath. From the
your Java code (which presumably Eclipse can find ok ;-))
needs jpl.jar (for jpl.Query etc), so add it as an external jar
which needs jpl.dll (JPL's native part), so add pl/bin to PATH
which needs swipl.dll (for SWIPL's FLI) (it too is in pl/bin)
which needs the rest of the SWI-Prolog installation.
Without a good reason to do otherwise, don't copy or move libraries around
your filestore, but link to them wherever they were installed.
If you first got the JPL examples working, you presumably already added pl/bin
to PATH? (or to LD_LIBRARY_PATH in Unix-like OSs)...
Hello!

Let's take a second try with JPL as I still can't get it to work (didn't
understand most of the discussion).

No libraries have been moved (IFAIK), everything is where have been put by the
installers.

In Netbeans I have created a Java project. In that project's Libraries -> Add
Library -> Create I have created a library "SWI-Prolog" with a Classpath
"C:\Program Files\SWI-Prolog\lib\jpl.jar". In that same library I've added
another Classpath pointing to "C:\Program Files\SWI-Prolog\bin". Now in my
project's libraries I see:
- SWI-Prolog - jpl.jar
- META-INF
MANIFEST.MF
- jpl
Atom.class
Compound.class
...
Version.class
- jpl.fli
BooleanHolder.class
DoubleHolder.class
...
term_t.class
- SWI-Prolog - C:\Program Files\SWI-Prolog\bin
- <default package>
cgi.dll
crypt.dll
...
zlib4pl.dll
- JDK 1.6 (Default)

What I'm missing/done wrong as I get an error when trying to run Fred Dushin's
JPL demo, dated 1998:
"
java.lang.NoClassDefFoundError: SWI_HOME_DIR=c:\Program
Files\SWI-Prolog;-Djava/library/path=c:\Program Files\SWI-Prolog\lib Caused by
java.lang.ClassNotFoundException: SWI_HOME_DIR=c:\Program
Files\SWI-Prolog;-Djava/library/path=c:\Program Files\SWI-Prolog\lib
"
and a bunch of locations ("at java...").

In Eclipse I have added a user library "SWI-Prolog" pointing to "C:\Program
Files\SWI-Prolog\lib\jpl.jar" (resulting under the project in the same folder
structure as with Netbeans; no, I haven't mix Netbeans and Eclipse projects,
they have different workspaces), but I don't know how to add a reference to
"C:\Program Files\SWI-Prolog\bin" as Eclipse wants a JAR, not accepting a folder
(I most likely have wrong dialog). This time I get no error messages but a
rather subtle message "3.1.4-alpha".

Help appriciated,

Juha "Metsis" Metsäkallas

----
Platform: MS Windows Vista 32 bit

Loading...