Java代码:ScriptEngineManagermanager=newScriptEngineManager();ScriptEngineengine=manager.getEngineByName(scriptEngineName);InputStreamin=newFileInputStream(jrubyFilePath)...
Java代码:
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName(scriptEngineName);
InputStream in = new FileInputStream(jrubyFilePath);
Object result = null;
result = engine.eval(new InputStreamReader(in));
Invocable invocable = (Invocable)engine;
Object strArray = new String[] {"hello","hi"};
ret = invocable.invokeMethod(result, "test", strArray);
System.out.println((String)ret);
Jruby代码:
class RmiRequestGenerator
def test(str)
str = Array(str)
return 'input param is Not an Array' unless str.is_a?(Array)
str.each do |word|
puts 'from jruby ' + word
end
end
end
RmiRequestGenerator.new
现在是可以取到JAVA数组里的值,但会抛异常如下:
Exception in thread "main" java.lang.ClassCastException: org.jruby.RubyArray cannot be cast to java.lang.String
at strIndex.StrIndex.main(StrIndex.java:78)
请问该怎么解决
展开