Executing from ant: "Provider com.sun.script.javascript.RhinoScriptEngineFactory not found"

StackOverflow https://stackoverflow.com/questions/14518438

  •  05-03-2022
  •  | 
  •  

Question

I'm developing an application that use JSR 223.

All are ok (unit test and the execution from command line), except when execution is from Ant. In this case, execution through this error:

ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider com.sun.script.javascript.RhinoScriptEngineFactory not found

JDK7 includes an implementation of Rhino and i'm sure this class is in rt.jar. Why have not found when Ant is used for execution?

JDK version: java version "1.7.0_11" Java(TM) SE Runtime Environment (build 1.7.0_11-b21) Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

ANT version: Apache Ant(TM) version 1.8.4 compiled on May 22 2012

Thanks

TEST:

package testing;

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

public class TestingGetEngineJavascript {

    public static void main(String[] args) {
        new TestingGetEngineJavascript().test();

    }

    public void test() {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");
        if(engine == null) {
            throw new RuntimeException("Upps!!!!!!! Not ScriptEngine found for JavaScript");
        } else {
            System.out.println("ScriptEngine found for JavaScript");
        }
    }

}


<project name="test" default="test" basedir=".">
    <target name="test">
        <java classpath="dist/testAntJSR223.jar" classname="testing.TestingGetEngineJavascript">
        </java>
    </target>
</project>
Was it helpful?

Solution 2

There are a "temporal" workaround: use fork="true"

But I think that it's a bug: https://issues.apache.org/bugzilla/show_bug.cgi?id=54484

OTHER TIPS

You can try initializing with this: ScriptEngineManager manager = new ScriptEngineManager(null);

I needed to include :

to make similar example work...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top