Search code examples
javascriptjava-8wildfly-8rhino

Wildfly 8.2 - ScriptEngineManager.getEngineFactories is empty on server startup


I am facing a weird behavior with Wildfly 8.2.1 running on Java 8 (Open JDK). I am specifically mentioning Java 8, because I did not see this issue on Java 7.

While my Wildfly module is being started, I have code that loads up JavaScripts using the Java RhinoScriptEngine.

    List<ScriptEngineFactory> engineFactories = engineManager.getEngineFactories();
    ScriptEngine scriptEngine = engineManager.getEngineByName("js");

Since scriptEngine was being assigned as null, I added debug logs and noticed that engineFactories is just an empty List(well, the engineFactories itself is being fetched only for debugging purposes). But, after the startup of the module is complete, this exact code works, and lists the RhinoScriptEngineFactory.

Is there something that has been changed in Java 8 that Wildfly 8.2 is not aware of, or do I need to add explicit dependencies to my module?


Solution

  • Script engine manager uses the service provider mechanism to enumerate all the implementations of ScriptEngineFactory. ScriptEngineFactory service descriptions are searched in resources accessible from

    1. Thread.currentThread().getContextClassLoader() - when construct ScriptEngnineManage without parameter
    2. Bootrap class loader - when construct ScriptEngnineManager with null parameter
    3. Class loader - when construct swith specific class loader

    How do you create ScriptEngineManager?

    If you construct ScriptEngineManager without parameters: What return Thread.currentThread().getContextClassLoader() when module is booting and when module boot is completed?

    Can you attach (upload to pastebin or somewhere) module.xml for you module?

    In java 8 rhino script engine was replaced by nashorn script engine. Do you really get RhinoScriptEngineFactory after module is loaded? Or it is NashornScriptEngine?