문제

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top