ScriptEngineManager.getEngineFactories does not return any factories in appengine

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 a development environment, but is not deployed.
Even after adding js.jar from rhino to the lib folder and adding it to the class path, EngineFactories files were not found.

What am I doing wrong?

+4
source share
2 answers

GAE is a highly optimized Java runtime. Even if ScriptEngineManager is in the white list of supported classes, there is one more parameter left to make it work.

You need to register the Rhino service, I have the keys to archiving it, but not quite. To register a service, you must create the file "META-INF / services / javax.script.ScriptEngineFactory" with one line with the exact same class name Rhino that implements the ScriptEngineFactory interface. And my problem is that I cannot find this class.

If anyone knows, please edit.

+2
source

Yes, Daniel is right, you will need to use another JavaScript engine, such as Rhino. I posed a possible solution on a similar question (which is based on the solution given by Harsha R ): fooobar.com/questions/1382618 / ...

0
source

Source: https://habr.com/ru/post/1382615/


All Articles