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
end
end

I run this so I can generate the java class:

jrubyc --java ruby_service.rb

And then:

javac -cp full_classpath_here RubyService.java

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

What am I doing wrong?

Pablo

Is the question you are asking similar this post?
http://tommy.chheng.com/index.php/2010/06/call-a-jruby-method-from-java/

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

@tommychheng
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 (http://goo.gl/bmSIj), you don’t type by the
interface.

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]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs