Search code examples
javaclips

Calling a Java application from CLIPS


I have a runnable jar: help.jar, and I need to call it from a rule in CLIPS, as

(defrule ask-shape
    (not (shape ?))
    => 
    (bind ?answer (ask-question "What is the shape?"))
    (while (eq ?answer help) do
       (help) ;; calling the java function
       (bind ?answer (ask-question "What is the shape?")))
    (assert (shape ?answer)))

How can I do it?


Solution

  • Read the CLIPS Advanced Programming Guide for instructions on creating user-defined functions which will allow you to call C code from a CLIPS program (such as calling "(help)" in your ask-shape rule). Use a search engine and search for "how to call Java from C". You'll get hits like this: https://www.codeproject.com/Articles/22881/How-to-Call-Java-Functions-from-C-Using-JNI.

    Alternately if you don't need any interaction between CLIPS and the Java code you code use the system command from your rule: (system "java -jar help.jar").