Calling jruby class which implements a java interface from java

Hi,
I have a jruby class which implements a java interface and I want to
call it from Java.
JavaInterfaceExample.java:
interface JavaInterfaceExample{
void add(int a, int b);
}

JrubyAdderImpl.rb

require ‘java’
require ‘JavaInterfaceExample’

class JrubyAdderImpl
include JavaInterfaceExample

 def add(a, b)
     a+b
 end

end

JavaCallerApp.java

class JavaCallerApp {
public static void main(String[] args) {
JrubyAdderImpl jrubyClass = new JrubyAdderImpl();
System.out.println(“Adding 3+5=” + jrubyClass.add(3,5)); //
Display the string.
}
}

I compiled each class but the java caller class can’t find the method
implemented in Jruby:

$javac JavaInterfaceExample.java
$jrubyc JrubyAdderImpl.rb
$javac -cp /usr/local/jruby/lib/jruby.jar:. JavaCallerApp.java
JavaCallerApp.java:5: cannot find symbol
symbol : method add(int,int)
location: class JrubyAdderImpl
System.out.println(“Adding 3+5=” + jrubyClass.add(3,5)); //
Display the string.
^
1 error

Is this possible in JRuby? or does the dynamic typing get in the way?


@tommychheng
Programmer and UC Irvine Graduate Student
Find a great grad school based on research interests:
http://gradschoolnow.com


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Ok, so this is possible!
I posted the corrected example at
http://tommy.chheng.com/index.php/2010/06/call-a-jruby-method-from-java/
github example at GitHub - tc/call-jruby-from-java-example: Call JRuby from Java Example

@tommychheng
Programmer and UC Irvine Graduate Student
Find a great grad school based on research interests:
http://gradschoolnow.com

On 6/18/10 11:36 AM, Tommy C. wrote:

require ‘java’
JavaCallerApp.java
implemented in Jruby:
1 error

Is this possible in JRuby? or does the dynamic typing get in the way?


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email