我无法使用主类和ant 1.8.4在Oracle JVM的JDK7U10或JDK6U32上运行“ hello world”犀牛程序。我收到此错误:

ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider com.sun.script.javascript.RhinoScriptEngineFactory not found
...
[java] Caused by: java.lang.NullPointerException
[java]     at com.Test.main(Test.java:14)


我的代码是从文档中复制的,该错误发生在engine.eval上:

package com;

import javax.script.*;

public class Test {

    public static void main(String[] args) throws Exception {

        // create a script engine manager
        ScriptEngineManager factory = new ScriptEngineManager();
        // create a JavaScript engine
        ScriptEngine engine = factory.getEngineByName("JavaScript");
        // evaluate JavaScript code from String
        engine.eval("print('Hello, World')");

    }
}


我的lib目录中有rhino提供的js.jar以及我可能需要的ant必需软件包bsf.jar。请帮忙。

最佳答案

我知道这篇文章很旧,但是您可以尝试使用以下方法初始化ScriptEngineManager:

ScriptEngineManager manager = new ScriptEngineManager(null);

09-26 05:09