Using Apache Sling Scala 2.8 Script Engine

I am trying to use the Apache Sling Scala 2.8 Script Engine, recently updated last month. I came with Scala 2.7 along with the Sling Scala 2.7 Script Engine, and it worked fine. I encounter a problem when I try to use a new implementation. When I call the ScalaScriptEngine eval function, I always get a "Script execution error" due to a NullPointerException. Has anyone else worked with the new build of the Script engine and run into this too?

Thank! Stephen

+3
source share
1 answer

, - Scala . . https://issues.apache.org/jira/browse/SLING-1877.

, . 2.7.7, java- (.. Java.class.path) . 2.8 '-usejavacp'.

, Scala:

def testScalaScriptEngine() {
  val scriptEngineFactory = new ScalaScriptEngineFactory

  val settings = new ScalaSettings()
  settings.parse("-usejavacp")
  scriptEngineFactory.getSettingsProvider.setScalaSettings(settings)

  val scriptEngine = scriptEngineFactory.getScriptEngine

  val script = """
  package script {
    class Demo(args: DemoArgs) {
      println("Hello")
    }
  }
  """
  scriptEngine.getContext.setAttribute("scala.script.class", "script.Demo", ScriptContext.ENGINE_SCOPE)
  scriptEngine.eval(script)
}
+3

Source: https://habr.com/ru/post/1775326/


All Articles