2

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.

Community
  • 1
  • 1
Rohit
  • 5,631
  • 4
  • 31
  • 59

1 Answers1

2

try making the java class PUBLIC it worked for me.since the default is package-private

akshay1188
  • 1,647
  • 2
  • 17
  • 35