我试图在 ant 标签中使用最新版本的 Rhino,但它似乎使用与 JVM 捆绑在一起的 Rhino 版本。我尝试调整类路径以指定 Rhino 脚本 jar。目前,我已尝试以下操作:
<project default="hello" name="hello-world" basedir=".">
<target name="hello">
<script language="javascript">
<classpath>
<pathelement location="js.jar"/>
</classpath><![CDATA[
x=<hello><world/></hello>
]]></script>
</target>
</project>
请注意脚本中包含的 E4X 语法,该语法只能在 Mozilla 的 Rhino 中运行,而不是与 JVM 捆绑的语法。
js.jar 与 ant 脚本位于同一目录中。我还尝试将其重命名为 rhino.jar,因为我认为我已经看到了表明这是必要的文档。
当我运行它时,它给出以下错误:
javax.script.ScriptException:sun.org.mozilla.javascript.EvaluatorException:语法错误(#3)
因此,看起来它确实仍在使用 JVM 附带的 Rhino 版本。如何让它使用新版本?
我已经使用以下 Ant 项目让它工作:
<project default="hello" name="helloworld" basedir=".">
<target name="hello">
<script language="javascript" manager="bsf">
<classpath>
<fileset dir="rhino-lib" includes="*.jar"></fileset>
</classpath><![CDATA[
x=<hello><world/></hello>
echo = helloworld.createTask("echo");
for (i=1; i<=10; i++) {
echo.setMessage(i*i);
echo.perform();
}
echo.setMessage(x);
echo.perform();
]]></script>
</target>
</project>
您需要在 ./rhino-lib 中添加以下 jar:
- bsf.jar (bsf 2.4.0) http://commons.apache.org/proper/commons-bsf/download_bsf.cgi
-
commons-logging-1.1.1.jar http://commons.apache.org/logging/download_logging.cgi
-
js.jar(犀牛1.7R2) http://www.mozilla.org/rhino/download.html
不是最漂亮的,但它有效。我会多尝试一下,看看是否可以让它与 javax.script 一起工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)