4

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?

antony.trupe
  • 10,028
  • 10
  • 54
  • 81
  • I'm guessing you're using Rhino, but you don't say. You need to explicitly mention what library you're using, and show your imports. – Nick Johnson Nov 23 '11 at 04:15
  • @NickJohnson yeah, Rhino. I thought I did mention that. – antony.trupe Nov 23 '11 at 04:35
  • im running into the same issue. anyone had any luck with this? – Sam Oct 15 '12 at 20:40
  • @Sam No. I ended up not using javax.script, and instead go directly to org.mozilla.javascript for the necessary APIs. See http://code.google.com/p/antonytrupe/source/browse/development/src/games/com/antonytrupe/games/server/GameEngine.java, http://code.google.com/p/antonytrupe/source/browse/development/src/diskwars/com/antonytrupe/server/diskwars/API.java, and related for examples – antony.trupe Oct 16 '12 at 01:41

2 Answers2

3

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.

Daniel De León
  • 11,681
  • 5
  • 76
  • 66
0

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

Community
  • 1
  • 1
Ian
  • 7,090
  • 2
  • 43
  • 51