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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.