I'm new to Ruby & Jruby . I want to test some stuffs of jruby in java code
Here is my code :
import java.util.ArrayList;
import java.util.HashMap;
import org.jruby.embed.LocalVariableBehavior;
import org.jruby.embed.ScriptingContainer;
public class Test {
public static void main(String[] args){
ScriptingContainer container = new ScriptingContainer(LocalVariableBehavior.PERSISTENT);
Test t = new Test();
LogStatBean bean = t.new LogStatBean();
container.setHomeDirectory("classpath:/META-INF/jruby.home");
container.put("bean", bean);
container.runScriptlet("arr = [1, 2, 3, 4, 5, 6]");
container.runScriptlet("puts arr");
container.runScriptlet("bean.setOutput(arr) ");
System.out.println(bean.getOutput());
}
public class LogStatBean {
public ArrayList<HashMap<String, Object>> getOutput() {
return output;
}
public void setOutput(ArrayList<HashMap<String, Object>> output) {
this.output = output;
}
public ArrayList<HashMap<String, Object>> output;
}
}
I cannot set the java local variable with type ArrayList in jruby ,it raise an error
TypeError: cannot convert instance of class org.jruby.RubyArray to class java.util.ArrayList
(root) at <script>:1
What i have to do ?