Snippets

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

Updated by Sebastian Sardina

File SARL-FAQ.markdown Modified

  • Ignore whitespace
  • Hide word diff
 
 The problem was that SWI-Prolog come as a _relocatable_ app and the JPL library is therefore _run-path dependent_, causing the linking error when loaded without the proper run-path search paths. That is JPL does not know where SWI is.
  
-
-The problem is with `libswipl.dylib`, which is not installed in  `@executable_path/../swipl/lib/x86_64-darwin15.6.0/libswipl.dylib` but instead in `/usr/local/lib/swipl-7.7.19/lib/x86_64-darwin17.7.0/libswipl.dylib`
- 
 So, one way to solve this would to use a _not_ relocatable version of SWI-prolog such as the homebrew or macport installs. However, those do not include the JPL library. :-(
  
 The only option is therefore to manually remove the run-path dependencies from the lib using the `install_name_tool`: 
 
     brew install swi-prolog
 
-This will install prolog in `/usr/local/Cellar/`
+This will install prolog in `/usr/local/Cellar/swi-prolog`
 
 As the homebrew version does _not_ come with the JPL library (an issue on the homebrew github as been opened about this), the second step is therefore to buid the library from source. Alternatively, you can download the already compiled  [libjpl.dylib]() and copy it in:
 
     /usr/local/Cellar/swi-prolog/7.6.4/libexec/lib/swipl-7.6.4/lib/
 
-Then cd into this directory.
-
-The last step is to ensure all dependencies link of the lib are valid (and absolute):
-
-You can check all the dependencies paths using the command:
+Now we need to ensure all dependencies link of the lib are valid (and absolute).
+Then cd into this directory and check all the dependencies paths using the command:
 
     otool -L libjpl.dylib
 
 
     install_name_tool -change <the_invalid_path> <your_new_valid_path> libjpl.dylib
 
-After doing this your lib should not depend on any external run-path:
+Above, for example, the problem is with `libswipl.dylib`, which is not installed in  `@executable_path/../swipl/lib/x86_64-darwin15.6.0/libswipl.dylib` but instead in `/usr/local/lib/swipl-7.7.19/lib/x86_64-darwin17.7.0/libswipl.dylib`
+
+After doing this step using `install_name_tool`, your lib should not depend on any external run-path:
 
     libjpl.dylib:
      /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/server/libjsig.dylib (compatibility version 1.0.0, current version 1.0.0)
Updated by Sebastian Sardina

File SARL-FAQ.markdown Modified

  • Ignore whitespace
  • Hide word diff
 # SWI-PROLOG
 
 
+## MAKING JPL WORK IN Mac OS
 
+(notes from student The Champion in the context of my AOPD course in 2018)
+ 
+There is an issue with using JPL in Mac OS due to a linking error in JPL. Here Theo describes his solution (edited with some extra info): 
 
+The problem was that SWI-Prolog come as a _relocatable_ app and the JPL library is therefore _run-path dependent_, causing the linking error when loaded without the proper run-path search paths. That is JPL does not know where SWI is.
+ 
 
+The problem is with `libswipl.dylib`, which is not installed in  `@executable_path/../swipl/lib/x86_64-darwin15.6.0/libswipl.dylib` but instead in `/usr/local/lib/swipl-7.7.19/lib/x86_64-darwin17.7.0/libswipl.dylib`
+ 
+So, one way to solve this would to use a _not_ relocatable version of SWI-prolog such as the homebrew or macport installs. However, those do not include the JPL library. :-(
+ 
+The only option is therefore to manually remove the run-path dependencies from the lib using the `install_name_tool`: 
 
+    install_name_tool <old_path> <new_path> dynlib
 
+So the first step is to install a not relocatable version of SWI-prolog:
 
+    brew install swi-prolog
 
+This will install prolog in `/usr/local/Cellar/`
 
+As the homebrew version does _not_ come with the JPL library (an issue on the homebrew github as been opened about this), the second step is therefore to buid the library from source. Alternatively, you can download the already compiled  [libjpl.dylib]() and copy it in:
+
+    /usr/local/Cellar/swi-prolog/7.6.4/libexec/lib/swipl-7.6.4/lib/
+
+Then cd into this directory.
+
+The last step is to ensure all dependencies link of the lib are valid (and absolute):
+
+You can check all the dependencies paths using the command:
+
+    otool -L libjpl.dylib
+
+For example:
+
+    libjpl.dylib:
+    /Applications/SWI-Prolog.app/Contents/swipl/lib/x86_64-darwin15.6.0/libjpl.dylib:
+        @rpath/libjsig.dylib (compatibility version 1.0.0, current version 1.0.0)
+        @rpath/libjvm.dylib (compatibility version 1.0.0, current version 1.0.0)
+        @executable_path/../swipl/lib/x86_64-darwin15.6.0/libswipl.dylib (compatibility version 0.0.0, current version 7.6.4)
+        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
+
+
+If an entry is not a valid path on your system you can change it using the command:
+
+    install_name_tool -change <the_invalid_path> <your_new_valid_path> libjpl.dylib
+
+After doing this your lib should not depend on any external run-path:
+
+    libjpl.dylib:
+     /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/server/libjsig.dylib (compatibility version 1.0.0, current version 1.0.0)
+     /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/server/libjvm.dylib (compatibility version 1.0.0, current version 1.0.0)
+     /usr/local/lib/swipl-7.7.19/lib/x86_64-darwin17.7.0/libswipl.dylib (compatibility version 0.0.0, current version 7.7.19)
+     /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.50.4)
+
+
+Once all entries are valid, you can add the path to this library:
+
+    /usr/local/Cellar/swi-prolog/7.6.4/libexec/lib/swipl-7.6.4/lib/ 
+
+to your `java.path.libray` and it will, hopefully, link correctly: :-)
+  
+    java -Djava.library.path=/usr/local/Cellar/swi-prolog/7.6.4/libexec/lib/swipl-7.6.4/lib/x86_64-darwin17.3.0/
+ 
+The Java Virtual Machine (JVM) uses the `java.library.path` property in order to locate and load _native libraries_. 
+When a Java application loads a native library using the `System.loadLibrary()` method, the `java.library.path` is scanned for the specified library. 
+If the JVM is not able to detect the requested library, it throws an `UnsatisfiedLinkError`. 
+See [this tutorial](https://examples.javacodegeeks.com/java-basics/java-library-path-what-is-it-and-how-to-use/) for more explanation on that variable.
+
+
+You can also do this in Eclipse: 
+
+1. Select your project in the Package Explorer area and press a right click on it.
+2. Select `Build Path → Configure Build Path...` option.
+3. In the appearing window, select the `Libraries` tab.
+4. Then, expand the JRE System library option and select the Native library location.
+5. Click on the Edit... button at the right panel.
+6. Locate the required library and then click OK.
+ 
+And that's it, your project will link and run properly on Mac OS ;)
+
+Thanks Theo!
 
 
 
Updated by Sebastian Sardina

File SARL-FAQ.markdown Modified

  • Ignore whitespace
  • Hide word diff
 Within SARL developers' perspective, constructor statements should be redefined only if you want to set the value of a field that is final (`val` keyword), because it is mandatory regarding the semantic of the val keyword. 
 Consequently, the best practice is that all initializations should be within the `on Initialize`. They should avoid constructor definition.
 
+So, the "clean" way to access the agent owner is in the `install` method:
+
+	skill SWIJPL_KB_Prolog implements KB_Prolog {
+		var module_name : String
+
+			 def install {
+			   module_name = this.owner.ID.toString
+			 }
+	... 
+	}
+
Updated by Sebastian Sardina

File SARL-FAQ.markdown Modified

  • Ignore whitespace
  • Hide word diff
 
 If you think a question is worth putting it here, please let me know, I am happy to add it! THANKS!
 
------------------------
-## TABLE OF CONTENTS
-
 [TOC]
 
 -----------------------
Updated by Sebastian Sardina

File SARL-FAQ.markdown Modified

  • Ignore whitespace
  • Hide word diff
 -----------------------
 # MAVEN
 
+### How do I install a JAR dependency manually?
+
+Suppose your application need version `1.2.0.7.2` of artifact `sarl-agtcity-mw` from group id `org.bitbucket.ssardina-research`, but for some reason it cannot be gathered automatically from the cloud.
+Suppose you can get a hold of that dependency and obtain file `sarl-agtcity-mw.jar`. How do you install it in the repo? Here it is:
+
+	mvn install:install-file -Dfile=sarl-agtcity-mw.jar -DgroupId=org.bitbucket.ssardina-research \
+    	-DartifactId=sarl-agtcity-mw -Dversion=1.2.0.7.2 -Dpackaging=jar
+
 ### How do I tell maven to work offline (not check anything on the internet)?
 
 Use the `-o` option for offline mode (e.g., `mvn -o clean package`): <https://www.packtpub.com/mapt/book/application_development/9781785286124/8/ch08lvl1sec81/working-in-offline-mode>
  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.