开发者

Why the method is not called -- jRuby Rails3

开发者 https://www.devze.com 2023-01-30 01:42 出处:网络
I have this Java class class Dog { private String name开发者_C百科; public Dog() { name = \"Fido\"; }

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号