在ant脚本中使用最近的Rhino

jbe*_*rd4 3 ant rhino

我试图在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>
Run Code Online (Sandbox Code Playgroud)

请注意在脚本中包含E4X语法,该语法仅适用于Mozilla的Rhino,而不适用于与JVM捆绑的Rhino.

js.jar与ant脚本位于同一目录中.我也尝试将其重命名为rhino.jar,因为我认为我已经看到文档表明这是必要的.

当我运行它时,它会给出以下错误:

javax.script.ScriptException:sun.org.mozilla.javascript.EvaluatorException:语法错误(#3)

因此,它似乎仍然使用JVM附带的Rhino版本.如何让它使用新版本?

gro*_*odt 6

我已经使用以下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>
Run Code Online (Sandbox Code Playgroud)

您需要./rhino-lib中的以下jar:

不是最漂亮的,但它的确有效.我会尝试多一点,看看我是否可以使用javax.script.