Reputation: 2143
I'm having trouble trying to call a custom java class with JRuby:
"uninitialized constant Classifier::SentimentClassifier"
require 'java'
require 'lib/SentimentClassifier.jar'
class Classifier
def self.classify
classifier = SentimentClassifier.new
end
end
Upvotes: 1
Views: 2099
Reputation: 30330
There is a difference between a class being available to jRuby, and actively importing it into your program - see https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby.
require 'lib/SentimentClassifier.jar'
tells jRuby that you want to make the contents of that jar available to your program, but it doesn't import any classes itself.
It's the same in Java - adding a jar to your program's classpath is not the same as importing one of its classes (in fact it's a prerequisite - you can't import a class that isn't on the classpath).
You need to java_import
the fully-qualified name of your class:
require 'java'
require 'lib/SentimentClassifier.jar'
java_import 'com.yourpackage.SentimentClassifier';
class Classifier
def self.classify
classifier = SentimentClassifier.new
end
end
Upvotes: 2