Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created November 24, 2009 20:23
Show Gist options
  • Save thinkerbot/242177 to your computer and use it in GitHub Desktop.
Save thinkerbot/242177 to your computer and use it in GitHub Desktop.
CLIPSJNI via JRuby
# 1) Install JRuby
# http://jruby.org/
# 2) Download CLIPSJNI 6.30
# http://sourceforge.net/projects/clipsrules/files/CLIPS/
# 3) Put this file in the CLIPSJNI folder, then:
#
# % cd [CLIPSJNI folder]
# % jruby clips.rb
#
# == Notes
#
# The details of #3 are significant. I found that the dynamic library for
# CLIPSJNI must be in the working directory for jruby to properly load
# Environment. That means one of these files:
#
# * libCLIPSJNI.jnilib (mac)
# * CLIPSJNI.dll (windows, I think)
#
# What's really going on is that the dynamic library must be on the
# 'java.library.path'. It's not enough to be on the jruby LOAD_PATH.
#
# So lets say you wanted:
#
# clips.rb
# lib/
# CLIPSJNI.jar
# libCLIPSJNI.jnilib
#
# You would need:
#
# % jruby -Ilib -J-Djava.library.path=lib clips.rb
#
# Where -Ilib sets the jruby LOAD_PATH and -J-D... sets the java.library.path.
# I don't know how to set the java library path in code, but there must be a
# way.
include Java
require 'CLIPSJNI.jar'
include_class 'CLIPSJNI.Environment';
clips = Environment.new
clips.build %q{ (defrule red-light (light red) => (printout t "Stop" crlf)) }
clips.build %q{ (defrule green-light (light green) => (printout t "GO" crlf)) }
clips.assert_string "(light green)"
clips.run # should printout 'GO'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment