In order to run Codesnippet, mentioned in ( How to configure jsr223 scripting using scala as a scripting language ), I needed to make the following changes. I used scala 2.11.0-M4
public static void main(String args[]){ ScriptEngine engine = new ScriptEngineManager().getEngineByName("scala"); // Set up Scriptenvironment to use the Java classpath List nil = Nil$.MODULE$; $colon$colon vals = $colon$colon$.MODULE$.apply((String) "true", nil); ((IMain)engine).settings().usejavacp().tryToSet(vals);ScriptContext.ENGINE_SCOPE); engine.getContext().setAttribute("labelO", new Integer(4), ScriptContext.ENGINE_SCOPE); try { engine.eval("val label = labelO.asInstanceOf[Integer]\n"+ "println(\"ergebnis: \" + (2 + label ))"); } catch (ScriptException ex) { ex.printStackTrace(); } }
source share