I was able to get the below test app to run. I found this on the internet as
a post reply to Michael Duerig who is the developer of the sling scala
script engine, about classpath issues using the sling scala script engine.
Please let me know if this is sufficient. I am also trying to modify below
to use in a pivot app.
see line containing " settings.usejavacp.value = true" below.
package main.scala.pivot_scala
import javax.script.ScriptContext
import javax.script.ScriptEngine
import javax.script.ScriptEngineManager
import javax.script.ScriptException
import javax.script.SimpleBindings
import org.apache.sling.scripting.scala.ScalaScriptEngineFactory
import scala.tools.nsc.settings
/**
* Hello world!
*
*/
object HelloScala {
def main(args: Array[String]) {
println("Hello World!")
val mgr = new ScriptEngineManager
val engine = (new ScalaScriptEngineFactory).getScriptEngine
val settings = new scala.tools.nsc.Settings
settings.usejavacp.value = true
engine.put(ScalaScriptEngineFactory.SCALA_SETTINGS, settings)
val script = """
package script {
class Demo(args: DemoArgs) {
println("Hello from scala")
}
}
"""
engine.getContext.setAttribute("scala.script.class", "script.Demo",
ScriptContext.ENGINE_SCOPE)
try {
engine.eval(script)
//" package script {object Test {def main(args: Array[String]) =
{println(\"Hello, world from scala!\")}}}")
} catch {
case ex => ex.printStackTrace
}
}
}
--
View this message in context:
http://apache-pivot-users.399431.n3.nabble.com/Trying-to-run-a-scala-script-tp2738919p2790067.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.