Here's my full code:
import javax.script.*;
public class TestF {
public static void main(String[] args) throws Exception {
// create a script engine manager
ScriptEngineManager factory = new ScriptEngineManager();
// create a Nashorn script engine
ScriptEngine engine = factory.getEngineByName("nashorn");
// evaluate JavaScript statement
try {
engine.eval("print('Hello, World!');");
} catch (final ScriptException se) {
se.printStackTrace();
}
}
}
I'm using Arch and just downloaded Java and have the Java extension on VSCode. I can run any other programs in Java but have not installed any external modules/packages. Running the above program gives me
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "javax.script.ScriptEngine.eval(String)" because "<local2>" is null
It seems like factory.getEngineByName("nashorn") is returning null.
Do I need to externally download Nashorn? Because this says it's already included automatically. Or is nashorn not supported anymore? Because this says I can still use it. I'm using the latest version of Java18 from their official website.