2

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?

aathif
  • 156
  • 2
  • 15

1 Answers1

1

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?

CyberWasp
  • 361
  • 3
  • 13
  • It had to do with class loading. So, there were 2 issues - i) the rhino jars were part of another jboss module that my module depended on, this explained why it worked after the server startup was complete. ii) I was not passing the ClassLoader and it was using the current thread contexts loader, and apparently it did not have visibility to the dependent modules classes. I passed the ClassLoader that was used by a class that was a part of my module and it worked. – aathif Mar 24 '17 at 06:36