Powered by SmartDoc
ENGLISHJAPANESE

Installing Java, prolog, and the interface

SWI-prolog is an efficient prolog compiler/interpreter developed by Jan Wielemaker and his collegues at University of Amsterdam. We employ SWI-prolog as our prolog compiler/interpreter because it is runnable on various platforms including Solaris, Linux, and Windows9X. We will install SWI-prolog and the interface to Java.

You may notice that there is a binary package for installing SWI-prolog on Windows. We need, however, to compile it from source because we need the runtime environment, 'libpl.a', which will be created under '/usr/local/lib/pl-3.3.8/runtime', to add SWI-prolog the interface to Java, JPL.

We install Java Development Kit before installing SWI-prolog. After installing both jdk and SWI-prolog, we install JPL, a Java Interface to Prolog.

Java Development Kit

There is no drama in installing JDK. We install JDK1.2.2 for Windows provided by Sun Microsystems. Some people claim that the runtime environment provided by IBM runs faster than the one by Sun, but we take the safer side.(3)

Obtaining the package

Wherever you can find it.

Installation

We install jdk1.2.2 under 'C:\cygnus\usr\local\jdk1.2.2' and the runtime environment under 'C:\cygnus\usr\local\JavaSoft'.

Defining Java_Home

We do not test jdk. (It is very unlikely that you will encounter any problem with installation.) You should instead add the following line to 'c:\AUTOEXEC.BAT'.

Adding JAVA_HOME to AUTOEXEC.BAT
set JAVA_HOME=c:\cygnus\usr\local\jdk1.2.2

It is also convenient to set a path to the binaries of jdk under bin so that you can for example compile and execute java programs anywhere. Set the path as follows:

Setting a path to the binaries
set PATH=c:\cygnus\usr\local\jdk1.2.2\bin;%PATH%
Restart your PC when you have finished.

  1. I have recently installed JDK1.3 provided by Sun. It works fine and looks faster than JDK1.2.2.(27.7.2000)

Installing SWI-prolog

Downloading

You can down load the source from SWI-prolog download page. The latest is version 3.3.8 (1.12MB). Place the file, pl-3.3.8.tar.gz, under /tmp (i.e., c:\cygnus\tmp).

Installation

  1. Unpack pl-3.3.8.tar.gz by typing 'tar xvfz pl-3.3.8.tar.gz'
  2. Change directory to pl-3.3.8/src to execute './configure'. You will probably encounter an error message as below, 'Invalid configuration...'. We will avoid the problem later by editing a source file, say, 'pl-os.c'.
    An error while configuration
    /tmp/pl-3.3.8/src> ./configure
    creating cache ./config.cache
    checking for gcc... gcc
    checking whether the C compiler (gcc  ) works... yes
    checking whether the C compiler (gcc  ) is a cross-compiler... no
    checking whether we are using GNU C... yes
    checking whether gcc accepts -g... yes
    checking for ranlib... ranlib
    checking host system type... 
            Invalid configuration `i386-unknown-cygwin32': 
            system `cygwin32' not recognized
    checking for make... make
    (...to be continued)
    
  3. Check Makefile to edit if you like.
  4. Run 'make'. You will probably encounter the compilation problem with pl-os.c as shown below:
    A problem while compilation
    gcc -c -I. -I. -I./rc -Wall -O2   pl-os.c -o pl-os.o
    pl-os.c: In function `Which':
    pl-os.c:2608: warning: implicit declaration of function `okToExec'
    pl-os.c:2608: warning: assignment makes pointer from integer without a cast
    pl-os.c:2630: `PATHSEP' undeclared (first use in this function)
    pl-os.c:2630: (Each undeclared identifier is reported only once
    pl-os.c:2630: for each function it appears in.)
    pl-os.c:2631: warning: assignment makes pointer from integer without a cast
    pl-os.c:2646: warning: assignment makes pointer from integer without a cast
    make: *** [pl-os.o] Error 1
    /tmp/pl-3.3.8/src> 
    
  5. If this is the case, open the file, src/pl-os.c. You skip to Line 642 and comment out the line and Line 656 so that the part between the two lines are compiled.

    Lines to be amended in pl-os.c L624--656
    // #if unix (to be commented out)
    char *
    PrologPath(const char *p, char *buf)
    { strcpy(buf, p);
    
      return buf;
    }
    
    char *
    OsPath(const char *p, char *buf)
    { strcpy(buf, p);
    
      return buf;
    }
    // #endif /*unix*/ (to be commented out)
    

    You also need to comment out the lines Line 2567 and 2570 so that the lines between them are forced to compile in:

    The lines between 2567 and 2570 to edit
    // #if defined(OS2) || defined(__DOS__) || defined(__WINDOWS__) || defined(__WIN32__)
    #define EXEC_EXTENSIONS { ".exe", ".com", ".bat", ".cmd", NULL }
    #define PATHSEP ';'
    // #endif
    
  6. Type 'make clean' and then 'make' again.
  7. If nothing wrong happend, run 'make install'

Testing SWI-prolog

Once you have successfully compiled SWI-prolog, check if it works.

  1. Check if the executables are installed under /usr/local/bin as below:
    Checking the executables
    /tmp/pl-3.3.8/src> ls -l /usr/local/bin
    total 1767
    -rwxr-xr-x   1 fuji     unknown   3612344 Jun 15 21:48 emacs.exe*
    lrw-r--r--   1 fuji     unknown        33 Jun 21 14:09 pl -> ../lib/pl-3.3.8/bin/pl*
    lrw-r--r--   1 fuji     unknown        35 Jun 21 14:09 plld -> ../lib/pl-3.3.8/bin/plld*
    lrw-r--r--   1 fuji     unknown        35 Jun 21 14:09 plrc -> ../lib/pl-3.3.8/bin/plrc*
    /tmp/pl-3.3.8/src> 
    
  2. Invoke SWI-prolog in bash to test.
    Test SWI-prolog in bash
    c:/cygnus/home> pl
    Welcome to SWI-Prolog (Version 3.3.8)
    Copyright (c) 1990-2000 University of Amsterdam. 
    Copy policy: GPL-2 (see www.gnu.org)
    
    For help, use ?- help(Topic). or ?- apropos(Word).
    
    1 ?- write('Hello World!').
    Hello World!
    
    Yes
    2 ?- 
    
  3. You have now successfully installed SWI-prolog on your PC.
  4. Try 'man pl' on console, say, in Bash window. You will see the beginning of the manual.

Installing JPL

JPL is a Java Interface to Prolog, with which you can call SWI-prolog from within Java. JPL is developed by Fred Dushin. The package is available from Separately distributed packages for SWI-Prolog. The package is well documented, thus, I only explain how to install it on Windows.

Downloading

The package is available from Separately distributed packages for SWI-Prolog. Download the package from SWI-prolog site by clicking the sentence, "a local copy of the source (version 1.0.1, June 16, 1999) ", not 'JPL'. You will obtain a gzipped tar file called 'jpl-1.0.1.tar.gz'(as is on the 21st July, 2000).

Installation

Prerequisite

You have to install the following packages:

Points to note

We had better keep the followings in mind:

The difficult point lies in creating the DLL module of JPL because the package only provides us with a means to compile it for Unix platforms, where modules are loaded dynamically through the mechanism of shared library object. For our relief, Cygnus tools include the DLL tool, with which we can create DLL modules.

Tips and examples are found in GNU Win32 related projects written by Mumit Khan. Download first the file entitled as 'README.jni.txt' to read a brief introduction to compiling DLLs using Cygnus tools, which you can find as the sixth item of the list. Download 'java-jni-examples.tar.gz' if you want to take a look of the samples. (The README file is included in the package, too.) We are going to create our own Makefile by slightly modifying 'java-jni/c/Makefile.cyg' in the sample for C.

Compiling Java sources

We are going to compile Java sources by hand, not using Makefiles provided in the package of jpl-1.0.1 because the package is primary designed for installing it on Unix platforms, not for Windows.

You can unpack the archive, jpl-1.0.1.tar, wherever. We unpack it, for example, under /cygdrive/d/tmp in what follows. We are going to create the files, jpl.jar (a Java archive) and jpl.dll (the DLL), and copy them later to appropriate directories. Unpack the archive as follows:

Unpacking jpl-1.0.1.tar
/cygdrive/d/tmp> tar xvfz jpl-1.0.1.tar.gz
You must have created the following directories and files under jpl-1.0.1 as shown in figure[The directories and files of jpl]:
The directories and files of jpl
/cygdrive/d/tmp> ls jpl-1.0.1
ChangeLog    INSTALL            Makefile
README       TODO               demo/
doc/         export.script*     jsrc/
rules.mk     src/               stamp.script*
test/        version

The steps are depicted below:

  1. You first compile the sources under jsrc/jpl/fli, and
  2. go up to jsrc/jpl to make the directories, jsrc/jpl/jpl and jsrc/jpl/jpl/fli.
  3. Move the class files under jsrc/jpl/fli to jsrc/jpl/jpl/fli before
  4. compiling the sources under jsrc/jpl.
  5. Finally, move the class files under jsrc/jpl to jsrc/jpl/jpl.
Compiling sources
/cygdrive/d/tmp/jpl-1.0.1/jsrc/jpl/fli> javac *.java
/cygdrive/d/tmp/jpl-1.0.1/jsrc/jpl/fli> cd ..
/cygdrive/d/tmp/jpl-1.0.1/jsrc/jpl> mkdir jpl
/cygdrive/d/tmp/jpl-1.0.1/jsrc/jpl> mkdir jpl/fli
/cygdrive/d/tmp/jpl-1.0.1/jsrc/jpl> mv fli/*.class jpl/fli
/cygdrive/d/tmp/jpl-1.0.1/jsrc/jpl> javac *.java
/cygdrive/d/tmp/jpl-1.0.1/jsrc/jpl> mv *.class jpl

You must have created the class files under jsrc/jpl/jpl and jsrc/jpl/jpl/fli. The last thing to do is to make the archive of files under jsrc/jpl as shown in *unresolved*:

Archivining the files
/cygdrive/d/tmp/jpl-1.0.1/jsrc/jpl> jar cvf jpl.jar jpl
added manifest
adding: jpl/(in = 0) (out= 0)(stored 0%)
adding: jpl/fli/(in = 0) (out= 0)(stored 0%)
adding: jpl/fli/DoubleHolder.class(in = 226) (out= 182)(deflated 19%)
(... suppressed by Fujinami for readability)
adding: jpl/fli/IntHolder.class(in = 220) (out= 181)(deflated 17%)
adding: jpl/fli/LongHolder.class(in = 245) (out= 203)(deflated 17%)
adding: jpl/Version.class(in = 432) (out= 302)(deflated 30%)
/cygdrive/d/tmp/jpl-1.0.1/jsrc/jpl> ls -lt jpl.jar
-rw-r--r--   1 fuji     unknown     27613 Jun 22 13:45 jpl.jar
Check the size of 'jpl.tar' to see if you have successfully made the archive.

Installing the Java archive

Once you have successfully created the archive, 'jpl.jar', you can place it under an appropriate directory and extend your classpath in AUTOEXEC.BAT. Below we make a directory, /usr/local/lib/jpl, and place the jar file there (figure[Placing jpl.jar]).

Placing jpl.jar
/cygdrive/d/tmp/jpl-1.0.1/jsrc/jpl> mkdir /usr/local/lib/jpl
/cygdrive/d/tmp/jpl-1.0.1/jsrc/jpl> cp jpl.jar /usr/local/lib/jpl
You should then include the following line in AUTOEXEC.BAT (list[Setting Classpath to jpl.jar]).
Setting Classpath to jpl.jar
set CLASSPATH=c:\cygnus\usr\local\lib\jpl\jpl.jar
Restart your PC to take the change into effect.

Compiling C sources

Before compiling the source, 'jpl_fli_Prolog.c', under (d:/tmp/)jpl-1.0.1/src, we have to do the followings:

Installing jpl.dll

You can copy 'jpl.dll' to a directory that can be found by JVM, e.g., /usr/local/lib/jpl as follows:

Copy jpl.dll to an appropriate directory
/cygdrive/d/tmp/jpl-1.0.1/src> cp jpl.dll /usr/local/lib/jpl
/cygdrive/d/tmp/jpl-1.0.1/src> ls /usr/local/lib/jpl
jpl.dll
jpl.jar
/cygdrive/d/tmp/jpl-1.0.1/src> 

You have to of course include the directory into your PATH by editing your AUTOEXEC.BAT as follows:

The line to be included for extending your PATH
set PATH=c:\cygnus\usr\local\lib\jpl;%PATH%
Restart your PC to take the change into effect.

Testing JPL

JPL package includes test programs so that we can check if we have successfully installed JPL. For testing, change directory to jpl-1.0.1/test to compile and run Test.java program as follows:

Running Test.java
~> cd d:/tmp/jpl-1.0.1/test
/cygdrive/d/tmp/jpl-1.0.1/test> javac Test.java
/cygdrive/d/tmp/jpl-1.0.1/test> java Test
test 0...Warning: (/cygdrive/d/tmp/jpl-1.0.1/test/test.pl:4):
	Singleton variables: [X]
Warning: (/cygdrive/d/tmp/jpl-1.0.1/test/test.pl:10):
	Singleton variables: [X, Y]
Warning: (/cygdrive/d/tmp/jpl-1.0.1/test/test.pl:13):
	Singleton variables: [Y]
Warning: (/cygdrive/d/tmp/jpl-1.0.1/test/test.pl:16):
	Singleton variables: [Y]
% test.pl compiled 0.02 sec, 2,416 bytes
passed.
test 1...passed.
test 2...passed.
test 3...passed.
test 4...passed.
test 5...passed.
test 6...passed.
test 7...passed.
test 8...passed.
test 9...passed.
test 10...passed.
test 11...passed.
test 101...0123456789012345678901234567890
123456789012345678901234567890123456789012
345678901234567890123467890123456789012345
678901234567890123456789012345678901234567
890123456789012345678901234567890123456789
5passed.
No output visible?

Beaware that the output by Test.class may not be visible on Bash window. You should run the shell in Meadow if it is the case.

  1. You may encounter a problem if you run 'make -f Makefile.cyg' within Meadow using BASH due to the different ways to referr to directories between Cygnus tools and Meadow. That is, /home for Cygnus corresponds to C:\cygnus\home for Meadow. If you have a trouble at this last stage, use Bash window instead.