在 scala 中运行时,我无法Class
进入范围。ScriptEngine
nashorn
这是我尝试做的事情:
import javax.script.{ScriptEngine, ScriptEngineManager}
case class MyClass(id: Option[String], name: Option[String])
val manager: ScriptEngineManager = new ScriptEngineManager
val engine: ScriptEngine = manager.getEngineByName("nashorn")
var simpleScript: String =
"""
var myClass = new MyClass('myId', 'myName'); print(myClass.id);
"""`
engine.eval(simpleScript)
有谁知道如何MyClass
启动JavaScript
?
我得到以下异常:
javax.script.ScriptException: ReferenceError: "MyClass" is not defined in <eval> at line number 1`