Nashorn Standalone 15.3 engine returned is null
Attila Szegedi
szegedia at gmail.com
Thu Jul 15 20:11:13 UTC 2021
Can you check if this is specific to 15.3, or does it also not work with e.g. 15.2?
Attila.
> On 2021. Jul 15., at 12:49, Andreas Mueller <am at iit.de> wrote:
>
> Tested it again with listing the engine right befor getByName:
>
> List<ScriptEngineFactory> factories = manager.getEngineFactories();
> for (int i = 0; i < factories.size(); i++) {
> ctx.logSwiftlet.logInformation(ctx.streamsSwiftlet.getName(), "name=" + factories.get(i).getEngineName() +
> ", version=" + factories.get(i).getEngineVersion() + ", language name=" + factories.get(i).getLanguageName() +
> ", language version=" + factories.get(i).getLanguageVersion() +
> ", names=" + factories.get(i).getNames());
> }
> engine = manager.getEngineByName((String) entity.getProperty("script-language").getValue());
>
> It is listed but returns null. This code is executed by a dedicated class loader.
>
> --
> Andreas Mueller
> IIT Software GmbH
> http://www.swiftmq.com <http://www.swiftmq.com/>
>
> <swiftmq_logo_positiv.png>
>
>> On 15. Jul 2021, at 10:59, Andreas Mueller <am at iit.de <mailto:am at iit.de>> wrote:
>>
>> Hi Attila,
>>
>> thanks but didn’t work in my environment.
>>
>> Tried every combination (using “nashorn”, “JavaScript” as name, using class path, using module path).
>>
>> Fact is, it lists the Nashorn engine correctly:
>>
>> ScriptEngineManager manager = new ScriptEngineManager();
>> List<ScriptEngineFactory> factories = manager.getEngineFactories();
>> for (int i = 0; i < factories.size(); i++) {
>> ctx.logSwiftlet.logInformation(ctx.streamsSwiftlet.getName(), "name=" + factories.get(i).getEngineName() +
>> ", version=" + factories.get(i).getEngineVersion() + ", language name=" + factories.get(i).getLanguageName() +
>> ", language version=" + factories.get(i).getLanguageVersion() +
>> ", names=" + factories.get(i).getNames());
>> }
>>
>> 2021-07-15 10:51:37.948/sys$streams/INFORMATION/name=OpenJDK Nashorn, version=15.3, language name=ECMAScript, language version=ECMA - 262 Edition 5.1, names=[nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript]
>>
>> But return null here:
>>
>> engine = manager.getEngineByName(“JavaScript”);
>>
>> I suspect it might have to do with class loaders as we use a dedicated class loader for every script:
>>
>> ScriptEngineManager manager = new ScriptEngineManager();
>> ClassLoader classLoader = createClassLoader();
>> streamContext.classLoader = classLoader;
>> Thread.currentThread().setContextClassLoader(classLoader);
>>
>> Thanks,
>> Andreas
>>
>> --
>> Andreas Mueller
>> IIT Software GmbH
>> http://www.swiftmq.com <http://www.swiftmq.com/>
>>
>> <swiftmq_logo_positiv.png>
>>
>>> On 13. Jul 2021, at 16:01, Attila Szegedi <szegedia at gmail.com> wrote:
>>>
>>> I’m honestly not sure. I have this very small test program:
>>>
>>> import javax.script.*;
>>>
>>> public class X {
>>> public static void main(String[] args) throws ScriptException {
>>> ScriptEngineManager factory = new ScriptEngineManager();
>>> ScriptEngine engine = factory.getEngineByName("JavaScript");
>>> engine.eval("function f() { print('Hello, World!'); } f()");
>>> }
>>> }
>>>
>>> if I put it in a directory where I checked out Nashorn repo, and run “ant jar” to build the JAR file and run:
>>>
>>> java --module-path build/nashorn/dist:build/nashorn/dependencies X.java
>>>
>>> It prints "Hello, World!” as expected, so it definitely find the engine under the name “JavaScript". I can also run it with classpath instead of module path:
>>>
>>> java -cp build/nashorn/dist/nashorn.jar:build/nashorn/dependencies/asm-7.3.1.jar:build/nashorn/dependencies/asm-util-7.3.1.jar X.java
>>>
>>> and that works too. Do you have the dependencies (ASM) too?
>>>
>>> Attila.
>>>
>>>> On 2021. Jul 13., at 15:33, Andreas Mueller <am at iit.de> wrote:
>>>>
>>>> Hi,
>>>>
>>>> I’ve added Nashorn to Java 15 and it is properly displayed when listing the engines:
>>>>
>>>> 2021-07-13 15:14:30.233/sys$streams/INFORMATION/starting, available Scripting Engines:
>>>> 2021-07-13 15:14:30.246/sys$streams/INFORMATION/name=OpenJDK Nashorn, version=15.3, language name=ECMAScript, language version=ECMA - 262 Edition 5.1, names=[nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript]
>>>>
>>>> However, when I get the engine with name “JavaScript” it returns null:
>>>>
>>>> engine = manager.getEngineByName((String) entity.getProperty("script-language").getValue());
>>>> if (engine == null)
>>>> throw new Exception("Engine for script-language '" + entity.getProperty("script-language").getValue() + "' not found!");
>>>>
>>>> 2021-07-13 15:14:30.361/ERROR/Exception occured: java.lang.Exception: Engine for script-language 'JavaScript' not found!
>>>>
>>>> Any ideas what the problem could be?
>>>>
>>>> Thanks,
>>>> Andreas
>>>> --
>>>> Andreas Mueller
>>>> IIT Software GmbH
>>>> http://www.swiftmq.com <http://www.swiftmq.com>
>>>>
>>>>
>>>
>>
>
More information about the nashorn-dev
mailing list