I have this Java class
class Dog {
private String name开发者_C百科;
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
精彩评论