Forum: JRuby Strange error when calling into jruby1.2 from java using javax.scripting ??

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
M C (Guest)
on 2009-04-12 01:01
(Received via mailing list)
I am trying to get jruby1.2 working with the new scripting api on JDK1.6
(JSR 223) but I have run into a strange error with the returned jruby
object not properly implementing a specified java interface. Can anyone
on the list help?

The error I get is an undefined method error as shown below about a
undefined method which is on an interface that the jruby object has been
asked to implement???  As can be shown further below, the jruby code
does implement the interface so it is a bit strange.

First the error that I get:

javax.script.ScriptException: org.jruby.exceptions.RaiseException:
undefined method `clear' for #<Java::JavaObject:0x2b1d8f11>
    at $Proxy14.clear(Unknown Source)

My jruby 1.2 script is as follows:
require 'java'
module Example
  import java.util.Properties # type of config arg
  import com.rv.Service # implementing interface
  import com.rv.Store # type of store arg
  import com.rv.TaskCoordinator # type of coordinaterCallback arg
  class RubyService
      include com.rv.Service
      def restore(store, config, coordinaterCallback)
        puts "Restore called"
      def clear(config, coordinaterCallback)
        puts "Clear called"


And the java script engine code extract:
ScriptEngine engine = scriptManager.getEngineByName("jruby")
Invocable invocable = (Invocable)engine;
ScriptContext context = engine.getContext();
BufferedReader scriptReader = ...

Object rawResult=engine.eval(scriptReader, context);

com.rv.Service rubyService=invocable.getInterface(rawResult,
rubyService.clear(null, null); # This line fails with the exception
shown above!!

Finally, here is the java interface with the clear method:
package com.rv;
public interface Service
    void restore(Store store, Properties config, TaskCoordinator
coordinaterCallback) throws CoreException, InterruptedException,

    void clear(Properties config, TaskCoordinator tc) throws
CoreException, InterruptedException, IOException;

Any idea why this happens?

P.S: The code extracts here are just extracts from a large piece of SW.

      Trænger du til at se det store billede? Kelkoo giver dig gode
tilbud på LCD TV! Se her
This topic is locked and can not be replied to.