Implementing a Java Interface

Hey guys,

I have a ruby class that implements a java interface, like this:

require ‘java’
java_package ‘net.jruby.test’
java_import “net.jruby.test.Service”

class RubyService
#implement this java interface
include Service

def sum(a,b)
a + b

I run this so I can generate the java class:

jrubyc --java ruby_service.rb

And then:

javac -cp full_classpath_here

Up to here, everything’s cool… the thing is: the generated .java file
(and consequently the .class file) DOES NOT implement the stated

What am I doing wrong?


Is the question you are asking similar this post?

you may need to add a signature like:
java_signature ‘int sum(int, int)’

On Friday, March 4, 2011 at 6:49 PM, pablo fernandez wrote:
Hey guys,

Actually that doesn’t help.

Now the generated sum method signature is correct, but the class still
doesn’t implement the interface I’m setting with ‘include Service’

The generated class looks like this:

  public class RubyService extends RubyObject  {

When ideally should look like this:

 public class RubyService extends RubyObject implements Service {

Also in your blog post (, you don’t type by the

If you change the last snippet to

JavaInterfaceExample jrubyImpl = new JrubyAdderImpl();

You’ll see the exact error I’m getting

On Sat, Mar 5, 2011 at 10:32 AM, pablo fernandez
<[email protected]

Found the answer, instead of this:

include Service

I needed this:

java_implements ‘Service’

On Sat, Mar 5, 2011 at 10:36 AM, pablo fernandez
<[email protected]