[jruby-user] How to use GEM from Java application
Shailesh Gala <[email protected]>
| Newsgroups | gmane.comp.lang.jruby.user |
|---|---|
| Message-ID | <[email protected]> |
I am newbie to JRuby. Most of our development is done as Java App, but
for some features we would like to use JRuby scripting. I was able to
get standard RUBY script to run from our App, but when I try to perform
require of GEM, I am getting error.
For e.g., If I have simple Ruby file like test.rb, the following Java
code runs fine after I add jruby.jar as external JAR in my Java project.
TEST.RB
========
puts "Hello World!!!"
TEST.JAVA
=========
package test;
import java.io.FileNotFoundException;
import org.apache.bsf.BSFException;
import org.apache.bsf.BSFManager;
import org.jruby.embed.PathType;
public class BsfLoadPathSample {
private final static String jrubyhome = "c:/jruby";
private final String filename = jrubyhome + "/samples/test.rb";
private BsfLoadPathSample() throws BSFException, FileNotFoundException
{
BSFManager.registerScriptingEngine("jruby",
"org.jruby.embed.bsf.JRubyEngine", new String[] {"rb"});
BSFManager manager = new BSFManager();
manager.setClassPath(jrubyhome);
manager.exec("jruby", filename, 0, 0, PathType.ABSOLUTE);
}
public static void main(String[] args) throws BSFException,
FileNotFoundException {
new BsfLoadPathSample();
}
}
BUT when I run this RB file,
FUZZY.RB
========
require 'fuzzystringmatch'
jarow = FuzzyStringMatch::JaroWinkler.create( :pure )
p jarow.getDistance( "jones", "johnson" )
(by changing test.rb to fuzzy.rb )
I GET FOLLOWING ERROR
=====================
LoadError: no such file to load -- fuzzystringmatch
require at org/jruby/RubyKernel.java:1057
(root) at c:/jruby/samples/fuzzy.rb:1
Oct 13, 2014 5:11:34 PM org.apache.bsf.BSFManager exec
HOW DO I get Java App to look into GEM files? Is there way to compile
GEMS into JAR file that I can include in my Java project? Any other
approaches.
I am using JRuby 1.7.16
Thanks
--
Posted via http://www.ruby-forum.com/.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email