Why the method is not called — jRuby Rails3
-
10-10-2019 - |
문제
I have this Java class
class Dog {
private String name;
public Dog() {
name = "Fido";
}
public String getName() {
return name;
}
}
And as mentioned here I have performed these steps
1. Compile the class.
mkdir classes
javac -d classes src/Dog.java
2.Add classes to the classpath in your Rails application (an initializer for example).
require 'java'
$CLASSPATH << File.join(Rails.root, "classes")
3.Import the class.
java_import Java::Dog
But still I am not able to access the getName()
method in rails 3 with the NoMethodError
, but the method is accesible in jRuby.
해결책
try making the java class PUBLIC it worked for me.since the default is package-private
제휴하지 않습니다 StackOverflow