在 ant 脚本中使用最新的 Rhino

发布于 2024-09-15 08:41:58 字数 836 浏览 12 评论 0原文

我试图在 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)

因此,它看起来似乎仍在使用附带的 Rhino 版本与 JVM 一起。如何让它使用新版本?

I'm trying to use a recent version of Rhino in an ant tag, but it seems to be using the version of Rhino that comes bundled with the JVM instead. I've tried adjusting the classpath to specify the Rhino script jar. Currently, I've tried the following:

<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>

Notice the inclusion of E4X syntax in the script, which should work only work in Rhino from Mozilla, and not the one bundled with the JVM.

js.jar is in the same directory as the ant script. I've also tried renaming it to rhino.jar, as I think I've seen documentation that suggested that this was necessary.

When I run it, it gives the following error:

javax.script.ScriptException: sun.org.mozilla.javascript.EvaluatorException: syntax error (#3)

So, it does appear as though it is still using the version of Rhino that comes with the JVM. How can I make it use the new version?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橙幽之幻 2024-09-22 08:41:58

我已经使用以下 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:

不是最漂亮的,但它有效。我会多尝试一下,看看是否可以让它与 javax.script 一起工作。

I've got it working using the following Ant project:

<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>

You need the following jars in ./rhino-lib:

Not the prettiest, but it works. I will try a bit more to see if I can get it to work with javax.script.

弃爱 2024-09-22 08:41:58

请参阅 Ant 用户邮件列表中的以下响应: http:// /mail-archives.apache.org/mod_mbox/ant-user/201008.mbox/browser

See the following response on the Ant user's mailing list: http://mail-archives.apache.org/mod_mbox/ant-user/201008.mbox/browser

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文