In the sbt console, sbt version 0.13.5, Scala version 2.11.1, I can get javax.script.ScriptEngine
for Scala:
scala> val engine = new javax.script.ScriptEngineManager().getEngineByName("scala")
engine: javax.script.ScriptEngine = scala.tools.nsc.interpreter.IMain@bf78a9
However, I can't use it:
scala> engine.eval("3")
[init] error: error while loading Object, Missing dependency 'object scala in compiler mirror', required by /usr/lib/jvm/java-7-openjdk-i386/jre/lib/rt.jar(java/lang/Object.class)
Failed to initialize compiler: object scala in compiler mirror not found.
** Note that as of 2.8 scala does not assume use of the java classpath.
** For the old behavior pass -usejavacp to scala, or if using a Settings
** object programatically, settings.usejavacp.value = true.
scala.reflect.internal.MissingRequirementError: object scala in compiler mirror not found.
at ...
According to the SBT FAQ, I am supposed to do some magic with a Settings
, and then pass it into my Interpreter
's constructor. However, I'm not directly creating an Interpreter
(and it's not even clear if I'm indirectly creating it, as the engine object is an IMain
).
Is there some way for the Scala ScriptEngine
to work on the SBT console?
sbt -Dscala.usejavacp=true console
makes getEngine fail. I think the change for jsr223 made classpath tweaks that deserve review. Thx for the gist link, I hadn't seen the history. – Mountaineer