I’m attempting to use a JNI provided by somebody else (CLIPS).
Basically I
need to require a jar and then include a Java class into my JRuby
environment. When my folder is setup like this it all works:
script.rb
CLIPSJNI.jar
libCLIPSJNI.jnilib
[script.rb]
include Java
require ‘CLIPSJNI.jar’
include_class ‘CLIPSJNI.Environment’
puts Environment
% jruby script.rb
Java::CLIPSJNI::Environment
However when I setup like this I get an error:
script.rb
lib/
CLIPSJNI.jar
libCLIPSJNI.jnilib
% jruby script.rb
(eval):1:in `include_class’: cannot link Java class
CLIPSJNI.Environment,
probable missing dependency: no
CLIPSJNI in java.library.path (NameError)
I can fix it by setting java.library.path from the command line:
% jruby -J-Djava.library.path=lib clips.rb
Java::CLIPSJNI::Environment
So how can I set java.library.path within my script so I don’t need the
command line flag? I’ve tried:
current = java.lang.System.getProperty(“java.library.path”)
java.lang.System.setProperty(“java.library.path”,
“#{current}:#{File.expand_path(‘lib’)}”);
And:
java.lang.System.load(File.expand_path(‘lib/libCLIPSJNI.jnilib’));
No luck so far. Any ideas? Thanks.