Here is my Rhino Wrapper, FWIW. (download)
From your example it’s not exactly clear what you’re trying to do, it’s just a big mess
I see how feeling to have to write such code can be demotivating.
Here is how I grab the results of File.list() from JS:
public static void main(String[] args)
{
try
{
JsScope scope = new JsScope();
System.out.println(scope.eval("importClass(Packages.java.io.File)"));
System.out.println(scope.eval("var file = new File('M:/');"));
System.out.println(scope.eval("var list = file.list();"));
String[] list = scope.getVariable("list", String[].class);
System.out.println(list);
System.out.println(list.length);
}
catch (JavaScriptException exc)
{
System.err.println("Exception: Line " + exc.lineNumber() + ": " + exc.getMessage());
}
catch (EvaluatorException exc)
{
System.err.println("Line " + exc.lineNumber() + ": " + exc.getMessage());
}
}