ScriptEngineManager.getEngineFactoriesreturns no factories on appengine

1.2k views Asked by At

The following code returns an empty array.

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

ScriptEngineManager manager = new ScriptEngineManager();
List<ScriptEngineFactory> factories = manager.getEngineFactories();

It works in the development environment, but not deployed.
Even after adding js.jar from rhino to the lib folder and adding it to the classpath, no EngineFactories are found.

What am I doing wrong?

2

There are 2 answers

0
Daniel De León On

GAE is a Java runtime very optimized. Even with the ScriptEngineManager is in the whitelist of supported classes, there is still one setting left, to make it work.

You need register the Rhino service, I have clues to archive it but not exactly. To register the service you must create the file 'META-INF/services/javax.script.ScriptEngineFactory' with one line with the exactly class name of a Rhino class that implements the 'ScriptEngineFactory' interface. And my problem is that I can't find these class.

If someone know please edit.

0
Ian On

Yes, Daniel is right, you'll need to use another JavaScript engine such as Rhino. I've put a possible solution on a similar question (which builds on a solution given by Harsha R): https://stackoverflow.com/a/28408123/578821