Sbt 0.13 ScriptEngine is Null for getEngineByName(“JavaScript”)

喜夏-厌秋 提交于 2019-12-23 20:57:35

问题


When I run tests which use getEngineByName("JavaScript") in sbt 0.13 the method returns null. The safe code works fine with sbt 0.12.x.

Tried on different environments: Windows 7 and Mac - same problem.

I tried to manually set javaHome in sbt.

test:dependencyClasspath contains .ivy2/cache/rhino/js/jars/js-1.6R7.jar

Any idea what's wrong?


回答1:


Haha it turns out I had this problem myself a few months ago, and forgot all about it! But then I found this just now in my own source code:

// the (null) became necessary when we upgraded to sbt 0.13. I don't understand why.
// classloaders, go figure! - ST 8/26/13
val engine =
  (new javax.script.ScriptEngineManager(null))
    .getEngineByName("rhino")
    .ensuring(_ != null, "JavaScript engine unavailable")

So passing null to the ScriptEngineManager constructor is the fix...

...but I can't shed on any light on the underlying cause, except that I bet it's a classloader thing. Note that fork in run := true also makes the problem go away.



来源:https://stackoverflow.com/questions/20168226/sbt-0-13-scriptengine-is-null-for-getenginebyname-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!