Jump to content

[1.7.10] ScriptEngineManager is Returning Null for JavaScript


angellus

Recommended Posts

This is not an issue that is directly related to Forge, but it is something someone here might be able to help me with.

 

When we updated our mod to 1.7.10, we noticed some people started having issues with running our content scripts which we use for mob drops and some other things. Well, now, it is happening to everything. I am pretty sure now that everyone is on Java 8, it does not work for anyone. It does not even work in our dev environment anymore for intelliJ.

 

This is the code that is messing up and it seems that it is a pretty standard way of doing things. "getEngineByName" is returning null which is only support to happen if that Engine does not exist. Except JavaScript should exist.

 

import javax.script.*;
new ScriptEngineManager().getEngineByName("JavaScript");

 

UPDATE: After a lot more research, it looks like in Java 8 that nashorn.jar, which contains the JavaScript engine, is a Java Extension and it is not being loaded by the Minecraft Launcher. Does anyone know how to force load this extension using either Gradle or the code or something else? The mod is being built with JDK8 targeting JRE 8. If I load it inside of IntelliJ it all works fine, it is simply because the extension is not being loaded by the launcher.

Link to comment
Share on other sites

It looks like it might be modloader that is causing the issue.

 

The following code works in Java 7 in both IntelliJ AND Minecraft, whereas in Java 8, it only works in IntelliJ

import javax.script.*;
new ScriptEngineManager().getEngineByName("JavaScript");

 

However, if I tell ScriptEngineManager to use the Forge Mod Loader, it only works in Java 7 and no longer in Java 8 at all.

 

import cpw.mods.fml.common.Loader;
import javax.script.*;
new ScriptEngineManager(Loader.instance().getModClassLoader()).getEngineByName("JavaScript");

 

 

In Java 7, rhino.jar is located inside of JRE\lib, in Java 8, nashorn.jar is located in JRE\lib\ext. It looks like Forge is not loading the Java extension Jars.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.