Snippets

Sebastian Sardina FAQ for using SARL + SWI/JPL Prolog + Maven

Updated by Sebastian Sardina

File SARL-SWI-Maven-FAQ.markdown Modified

  • Ignore whitespace
  • Hide word diff
-# FAQ for using SARL + SWI Prolog + Maven
+# FAQ for using SARL + SWI Prolog (with JPL) + Maven
 
 This is a collection of questions/issues that arose from my teaching of Agent Oriented Programming, where I have assessments in [SARL](http://www.sarl.io/) and [SWI Prolog](http://www.swi-prolog.org/), all packaged with [Apache Maven](https://maven.apache.org/).
 
 -----------------------
 # ECLIPSE
 
+We use ECLIPSE to develop SARL applications.
+
+
 ### How do I make ECLIPSE know about environment variables (e.g., `SARL_VERSION`)?
 
 I can imagine there are other ways, but the way I made it work is by starting ECLIPSE from CLI with the variable exported already:
     * This will require first to install [Eclipse Dynamic Language Toolkit](https://projects.eclipse.org/projects/technology.dltk) (DLTK) 
         * You can use this update link: http://download.eclipse.org/technology/dltk/updates-dev/latest/
 
+# IntelliJ
+
+We use IntelliJ to develop pure Java applications.
+
+### When I run an application I get erro saying `no jpl in java.library.path`?
+
+IntelliJ cannot find the native library as it does not have `LD_LIBRARY_PATH` set correctly. See next question.
+
+
+### How do I tell IntelliJ about environment variables (like `LD_LIBRARY_PATH`)?
+
+You set environment variables (if not set already system-wide) for each run/debug configuration.
+
+Since it is painful to do it manually for each, one should first modify the Templates in "Run/Debug Configuration" to include the environment variables needed, for example `LD_PRELOAD`, `SWI_HOME_DIR`, and `LD_LIBRARY_PATH`. 
+
+See this [post](https://intellij-support.jetbrains.com/hc/en-us/community/posts/205820189-How-to-set-default-environment-variables-)
+
+For example, modify the JUnit template by just enter this string in "Environment variables":
+        
+       LD_LIBRARY_PATH=/usr/local/swipl-git/lib/swipl/lib/x86_64-linux/;SWI_HOME_DIR=/usr/local/swipl-git/lib/swipl/;LD_PRELOAD=libswipl.so
 
+Then, create a new Run from the template, and it will already inherit the environment variables.
 
 
 -----------------------
Updated by Sebastian Sardina

File SARL-SWI-Maven-FAQ.markdown Modified

  • Ignore whitespace
  • Hide word diff
 
 ### Making JPL work under Mac OS
 
-Please refer to [this entry](https://github.com/ssardina-research/packages-jpl/wiki/JPL-under-Mac-OS) in the JPL wiki.
+Please refer to [this entry](https://jpl7.org/DeploymentMacos) in the JPL documentation. (Note: that is from 2018; it may be fixed in newer versions)
 
 ### What does `+`, `-`, `?` mean in predicate specifications?
 
Updated by Sebastian Sardina

File SARL-SWI-Maven-FAQ.markdown Modified

  • Ignore whitespace
  • Hide word diff
 
 Basically you need to let the system know which SWI Prolog is installed and you want to use. 
 
+#### Linux
+
 If you are using a Linux distribution install, you would do something like this:
 
     export SWI_HOME_DIR=/usr/lib/swi-prolog/
     export LD_LIBRARY_PATH=$SWI_HOME_DIR/lib/x86_64-linux/:$SWI_HOME_DIR/lib/amd64/:$LD_LIBRARY_PATH
     export LD_PRELOAD=libswipl.so:$LD_PRELOAD   # only if necessary and your app complains
 
+#### Windows
+
+* A system variable `SWI_HOME_DIR` points to the root of SWI install.
+* System variable `Path` should include `%SWI_HOME_DIR%\bin` and `%SWI_HOME_DIR%\lib\jpl.jar`.
+
 
 ### My Java/SARL application cannot cannot find JPL!
 
 There could be many reasons and it may depend on the OS you are using. 
 
-First of all, make sure you have SWI-Prolog installed, either:
+First of all, make sure you have **SWI-Prolog installed**, either:
 
 * Stable version 7.6.4 as per standard Linux repository or executable install from SWI page.
 * Compiled 8.1.x+ version from [swipl-devel repo](https://github.com/SWI-Prolog/swipl-devel).
     * Note current (Feb 2019) stable 8.0.x version has a problem with `libswipl.so` which makes JPL crash.
 
-Second, make sure you also have the **JPL package** installed in the system. This is an additional SWI module, it is not part of the core.
+Second, make sure you also have the **JPL package installed** in the system. This is an additional SWI module, it is not part of the core.
 
 * In **Windows**, it is easy as you can click to install JPL Java<-->SWI interface at installation time. 
     * You should see `jpl.dll` file in `%SWI_HOME_DIR%/bin` and `jpl.jar` in `%SWI_HOME_DIR%/lib`.
     * In ARCH, you can generate it and install it using AUR package builder and `swi-prolog-git` package. Running the default PKG build file is enough to get JPL installed.
     * In MAC, we don't know how to make it work, as there is a glitch in one of the packages built for Mac... :-( [if you make it work, please let me know!]
 
-Finally, make sure your system is aware of both SWI and JPL:
-
-* In **Windows**, make sure:
-    * A system variable `SWI_HOME_DIR` points to the root of SWI install.
-    * System variable `Path` includes `%SWI_HOME_DIR%\bin` and `%SWI_HOME_DIR%\lib\jpl.jar`.
-* In **Linux**, make sure you set-up variables `LD_PRELOAD`, `SWI_HOME_DIR`, and `LD_LIBRARY_PATH` as per question before.
+Finally, make sure your system is aware of both SWI and JPL by setting the appropiate env variables; see previous above.
 
 If you are using SARL, you may also refer to the instructions of the [SARL Prolog Capacity](https://bitbucket.org/ssardina-research/sarl-prolog-cap)
 
Updated by Sebastian Sardina

File SARL-SWI-Maven-FAQ.markdown Modified

  • Ignore whitespace
  • Hide word diff
 
 ### What environment variables I should care about (in Linux)?
 
-Basically you need to let the system know which SWI Prolog is installed and you want to use. I run this in my Linux box as I have cloned the SWi git repo and installed it at `/usr/local/swipl-git`:
+Basically you need to let the system know which SWI Prolog is installed and you want to use. 
+
+If you are using a Linux distribution install, you would do something like this:
+
+    export SWI_HOME_DIR=/usr/lib/swi-prolog/
+    export LD_LIBRARY_PATH=$SWI_HOME_DIR/lib/x86_64-linux/:$SWI_HOME_DIR/lib/amd64/:$LD_LIBRARY_PATH
+    export LD_PRELOAD=libswipl.so:$LD_PRELOAD   # only if necessary and your app complains
+
+The reason why we have two library paths is that `lib/amd64/` is used for SWI 7.6.4, whereas `lib/x86_64-linux/` is used in 8.x.x versions.
+
+
+If, instead, you compiled the SWI from git sources and installed at `/usr/local/swipl-git`, you would do something like this:
 
     export SWI_HOME_DIR=/usr/local/swipl-git/lib/swipl/
     export LD_LIBRARY_PATH=$SWI_HOME_DIR/lib/x86_64-linux/:$SWI_HOME_DIR/lib/amd64/:$LD_LIBRARY_PATH
     export LD_PRELOAD=libswipl.so:$LD_PRELOAD   # only if necessary and your app complains
 
+
 ### My Java/SARL application cannot cannot find JPL!
 
 There could be many reasons and it may depend on the OS you are using. 
Updated by Sebastian Sardina

File SARL-SWI-Maven-FAQ.markdown Modified

  • Ignore whitespace
  • Hide word diff
 -----------------------
 # ECLIPSE
 
-## How do I make ECLIPSE know about environment variables (e.g., `SARL_VERSION`)?
+### How do I make ECLIPSE know about environment variables (e.g., `SARL_VERSION`)?
 
 I can imagine there are other ways, but the way I made it work is by starting ECLIPSE from CLI with the variable exported already:
 
 If you find another way that ECLIPSE can gather the environment variables (without re-defining them one by one), let me know! 
 
 
-## What plugins are useful to develop on SARL in ECLIPSE?
+### What plugins are useful to develop on SARL in ECLIPSE?
 
 On the SARL ECLIPSE distribution I install:
 
 * The types of queries available: [One-shot vs Iterative](https://github.com/ssardina-research/packages-jpl/wiki/Types-of-Queries:-One-shot-vs-Iterative)
 * How [multi-threading queries](https://github.com/ssardina-research/packages-jpl/wiki/Multi-Threaded-Queries) work under JPL.
 
-## Making JPL work under Mac OS
+### Making JPL work under Mac OS
 
 Please refer to [this entry](https://github.com/ssardina-research/packages-jpl/wiki/JPL-under-Mac-OS) in the JPL wiki.
 
-## What does `+`, `-`, `?` mean in predicate specifications?
+### What does `+`, `-`, `?` mean in predicate specifications?
 
 Check [here](http://www.swi-prolog.org/pldoc/man?section=preddesc)
 
-## What environment variables I should care about (in Linux)?
+### What environment variables I should care about (in Linux)?
 
 Basically you need to let the system know which SWI Prolog is installed and you want to use. I run this in my Linux box as I have cloned the SWi git repo and installed it at `/usr/local/swipl-git`:
 
 
 There could be many reasons and it may depend on the OS you are using. 
 
-First of all, _do you have the **JPL package installed** in the system?_
+First of all, make sure you have SWI-Prolog installed, either:
+
+* Stable version 7.6.4 as per standard Linux repository or executable install from SWI page.
+* Compiled 8.1.x+ version from [swipl-devel repo](https://github.com/SWI-Prolog/swipl-devel).
+    * Note current (Feb 2019) stable 8.0.x version has a problem with `libswipl.so` which makes JPL crash.
+
+Second, make sure you also have the **JPL package** installed in the system. This is an additional SWI module, it is not part of the core.
 
 * In **Windows**, it is easy as you can click to install JPL Java<-->SWI interface at installation time. 
     * You should see `jpl.dll` file in `%SWI_HOME_DIR%/bin` and `jpl.jar` in `%SWI_HOME_DIR%/lib`.
     * In ARCH, you can generate it and install it using AUR package builder and `swi-prolog-git` package. Running the default PKG build file is enough to get JPL installed.
     * In MAC, we don't know how to make it work, as there is a glitch in one of the packages built for Mac... :-( [if you make it work, please let me know!]
 
-Once JPL is in your system, you need to make the **system is aware** of it!
+Finally, make sure your system is aware of both SWI and JPL:
 
 * In **Windows**, make sure:
     * A system variable `SWI_HOME_DIR` points to the root of SWI install.
 
 ### Seems my SARL application cannot find JPL!
 
-There could be many reasons and it may depend on the OS you are using. 
-
-First of all, _do you have the **JPL package installed** in the system?_
-
-* In **Windows**, it is easy as you can click to install JPL Java<-->SWI interface at installation time. 
-    * You should get jpl.dll file in `%SWI_HOME_DIR%/bin` and `jpl.jar` in `%SWI_HOME_DIR%/lib`.
-* In **Linux**, you need to make sure `libjpl.so` and `jpl.jar` are somewhere! If you cannot find it, then you may need to install JPL. 
-    * In Ubuntu, it is provided with package `swi-prolog-java`. 
-    * In ARCH,  you can generate it and install it using AUR package builder and `swi-prolog-git` package. Running the default PKG build file is enough to get JPL installed.
-    * In MAC, we don't know how to make it work, as there is a glitch in one of the packages built for Mac... :-( [if you make it work, please let me know!]
-
-Once JPL is in your system, you need to make the **system is aware** of it!
-
-* In **Windows**, make sure:
-    * A system variable `SWI_HOME_DIR` points to the root of SWI install.
-    * System variable `Path` includes `%SWI_HOME_DIR%\bin` and `%SWI_HOME_DIR%\lib\jpl.jar`.
-* In **Linux**, make sure:
-    * `export LD_PRELOAD=libswipl.so:$LD_PRELOAD`
-    * `export LD_LIBRARY_PATH=/usr/lib/swi-prolog/lib/amd64/` (or wherever `libjpl.so` is located)
+There could be many reasons and it may depend on the OS you are using. You need to have SWI-Prolog, JPL package, and the right environment variables set-up.
 
-With this, your SARL application should be able to recognize where JPL is (hopefully!) :-)
+Check [this question](https://bitbucket.org/snippets/ssardina/9er67X#markdown-header-my-javasarl-application-cannot-cannot-find-jpl)
 
-You may also refer to the instructions of the [SARL Prolog Capacity](https://bitbucket.org/ssardina-research/sarl-prolog-cap)
 
 ### Strange error in CLI when using occurence on left hand side of assignments
 Consider this code:
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.