到目前为止,我已经尝试了 scala 的 jsr223 脚本的 sling 实现,但无法正确设置它。
当我这样做时:
public static void main(String[] args) {
try {
new ScriptEngineManager().getEngineByName("scala").
eval("object HelloWorld {def main(args: Array[String]) {
println(\"Hello, world!\") }}");
} catch (ScriptException e) {
e.printStackTrace();
}
}
我什么也没有得到,但是:
javax.script.ScriptException: ERROR
org.apache.sling.scripting.scala.Script line 13 : not found: type
Script at org.apache.sling.scripting.scala.ScalaScriptEngine.eval(ScalaScriptEngine.scala:117)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
这里讨论了类似的问题:
http://scala-programming-language.1934581.n4.nabble.com/How-to-compile-Scala-code-from-java -using-the-current-ClassLoader-instead-of-a-string-based-classpat-td1955873.html#a1955873
和
http://dev.day.com/discussion-groups/content/lists/sling-dev/2009- 12/2009-12-01_Scala_scripting_support_was_Re_And_another_one____Michael_D_rig.html
也许还有另一个我不知道的实现。
任何帮助表示赞赏
So far I have tried the sling implementation for jsr223 scripting for scala, but was not able to get it set up correctly.
when I do this:
public static void main(String[] args) {
try {
new ScriptEngineManager().getEngineByName("scala").
eval("object HelloWorld {def main(args: Array[String]) {
println(\"Hello, world!\") }}");
} catch (ScriptException e) {
e.printStackTrace();
}
}
I got nothing but:
javax.script.ScriptException: ERROR
org.apache.sling.scripting.scala.Script line 13 : not found: type
Script at org.apache.sling.scripting.scala.ScalaScriptEngine.eval(ScalaScriptEngine.scala:117)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
similar Problems are discussed here:
http://scala-programming-language.1934581.n4.nabble.com/How-to-compile-Scala-code-from-java-using-the-current-ClassLoader-instead-of-a-string-based-classpat-td1955873.html#a1955873
and
http://dev.day.com/discussion-groups/content/lists/sling-dev/2009-12/2009-12-01_Scala_scripting_support_was_Re_And_another_one____Michael_D_rig.html
maybe there is another Implementation that I'm not aware of.
Any help appreciated
发布评论
评论(3)
查看 Apache Sling 作为一个工作示例。脚本及其入口点(即对象)需要遵循某些约定。如果稍后需要,我将提供有关这些的更多信息。
有关脚本引擎的总体概述,请参阅我的 Scala Days 2010 会议幻灯片 。
更新:脚本必须采用以下形式:
args
的类型为Bindings 通过脚本评估包含名称“bar”的值。有关更多详细信息,请参阅ScalaScriptEngine
。您需要将脚本类的名称传递给脚本引擎。您可以通过将完全限定的脚本名称(即
my.cool.script.foo
)放入ScriptContext
,名称为“scala.script.class”。Have a look at the test cases in the scala/script module of Apache Sling for a working example. The script and its entry point (that is the object) need to follow certain conventions. I'll provide more information on these if required later.
For a general overview of the scripting engine see my session slides from Scala Days 2010.
Update: Scripts must be of the following form:
The type of
args
is generated by the script engine and is named after the simple class name of the script appended with 'Args'. Further the example assumes, that the Bindings passed for script evaluation contains a value for the name 'bar'. For further details see the class comment onScalaScriptEngine
.You need to pass the name of your script class to the script engine. You do this by putting the fully qualified script name (i.e.
my.cool.script.foo
) into theScriptContext
by the name 'scala.script.class'.随着 https://issues.scala-lang.org/browse/SI-874 的结论 在 2.11 版本中,它应该像票证中所示的那样简单:
With the conclusion of https://issues.scala-lang.org/browse/SI-874 in version 2.11, it should be as easy as what is shown in the ticket:
不幸的是,如果没有换行符,我的评论将无法阅读 - 所以...
为了能够运行提到的 Codesnippet,我需要进行以下更改。
我用的是Scala 2.11.0-M4
Unfortunately my comment was unreadable without linebreaks - so...
To be able to run the Codesnippet mentioned I needed to make the following changes.
I used Scala 2.11.0-M4