I'm trying to evaluate javascript in Java by using the ScriptEngine class. Here is a short example of what I am trying to do:
import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;
public class Test {
public static void main(String[] args) {
ScriptEngine engine = new ScriptEngineManager().getEngineByName(js); //Creates a ScriptEngine
Object obj = engine.eval(var obj = { value: 1 }; return obj; ); // Evals the creation of a simple object
System.out.println(obj.value); // I get an invalid token error when trying to print a property of the object
}
}
I'm pretty sure that this should work... but I'm stumped, and I'll take any help I can get.