尝试使用Rhino,getEngineByName(" JavaScript")在OpenJDK 7中返回null [英] Trying to use Rhino, getEngineByName("JavaScript") returns null in OpenJDK 7

查看:1200
本文介绍了尝试使用Rhino,getEngineByName(" JavaScript")在OpenJDK 7中返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行以下代码时,引擎变量在我使用时设置为 null OpenJDK 7( java-7-openjdk-i386 )。

When I run the following piece of code, the engine variable is set to null when I'm using OpenJDK 7 (java-7-openjdk-i386).

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class TestRhino {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        ScriptEngineManager factory = new ScriptEngineManager();
        ScriptEngine engine = factory.getEngineByName("JavaScript");
        try {
            System.out.println(engine.eval("1+1"));
        } catch (ScriptException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

它运行 java-6-openjdk 和Oracle的 jre1.7.0 。知道为什么吗?

It runs fine with java-6-openjdk and Oracle's jre1.7.0. Any idea why?

我正在使用Ubuntu 11.10。所有JVM都安装在 / usr / lib / jvm 下。

I'm using Ubuntu 11.10. All JVMs are installed under /usr/lib/jvm.

推荐答案

[更新:这是一个错误,现已已修复]

[Update: This was a bug, which has now been fixed]

简而言之,这可能是一个错误。

In short, this might be a bug.

Rhino支持类( com.sun.script.javascript。* )未编译成 rt.jar 1 (尽管我发现引用这是Sun和Mozilla之间的合并问题,我知道存在名称空间问题,它们确实存在于OpenJDK 7源代码中并在makefile中引用),并且它们在中缺失resources.jar META-INF / services 。这不是OpenJDK 6的情况,它将此作为 META-INF / services / javax.script.ScriptEngineFactory 条目:

Rhino support classes (com.sun.script.javascript.*) are not compiled into rt.jar1 (though I found references to this being a merging issue between Sun and Mozilla, and I know there have been namespace issues, they do exist in the OpenJDK 7 source and are referenced in the makefile), and they're missing from resources.jar's META-INF/services as well. This is not the case with OpenJDK 6, which has this as a META-INF/services/javax.script.ScriptEngineFactory entry:

#script engines supported

com.sun.script.javascript.RhinoScriptEngineFactory #javascript

虽然这可能是一个发行版决定 2 但没有书面理由,所以我提交了 Ubuntu OpenJDK 7启动板中的错误#982501 。一旦我拿到一个,我会给出更好的答案。

Though this might be a distro decision2 there is no written reason for it, so I filed a bug #982501 in the Ubuntu OpenJDK 7 launchpad. Will give a better answer once I get one.

1根据这个帖子


我听说过某个地方Mozilla不接受太阳队改变他们的
主线分支,原因不明但是在开源之前。

I had heard somewhere that Mozilla didn't accept Suns changes into their mainline branch for reasons unknown but that was prior to being opensourced.

由于JRE和BYOR(自带自带的Rhino)版本的冲突版本引起了一些冲突问题(例如 Ubuntu OpenJDK 7启动板上的错误#255149 )。但是,源代码位于OpenJDK 7 来源并在 makefile ,以及上面提到的线程中提到的BSD端口具有相同的来源

There have also been some collision issues caused by conflicting versions of JRE and a BYOR (bring-you-own-Rhino) version (e.g. bug #255149 on Ubuntu OpenJDK 7 launchpad). However, the source is in the OpenJDK 7 source and mentioned in the makefile, and BSD port, mentioned in the above thread, has identical sources.

2根据这个Sun bug#6876736 ,这是基于发行版的决定:

2 According to this Sun bug #6876736, this is to a distro-based decision:


犀牛来源不是OpenJDK的一部分,它取决于添加它的发行版。

The rhino sources are not part of OpenJDK, it is up to the distros to add it.

与此相反的事实与他们已经检查了OpenJDK mercurial,但我认为这个想法是Rhino不在JDK规范中。

Somewhat in contrast to the fact that they're checked in to the OpenJDK mercurial, but I think the idea is that Rhino is not in the JDK spec.

这篇关于尝试使用Rhino,getEngineByName(" JavaScript")在OpenJDK 7中返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆