javax.script.ScriptException: JavaScript implementation not found!

Question:

Hi guys, trying to use javascript implementation of GraalVM (JDK 17.0.5) for my java project.
Current behavior:
Looks like that the JVM of replit hasn t any Javascript implementation. That what was returned from the code after running
That is the code:

ScriptEngineManager manager2 = new ScriptEngineManager();
    ScriptEngine engine2 = manager2.getEngineByName("javascript");
    try {
      Double hour = (Double) engine2.eval("var date = new Date();" + "date.getHours();");
      String msg;
      if (hour < 10) {
        msg = "Good morning";
      } else if (hour < 16) {
        msg = "Good afternoon";
      } else if (hour < 20) {
        msg = "Good evening";
      } else {
        msg = "Good night";
      }
      System.out.println(hour);
      System.out.println(msg);
    } catch (ScriptException e) {
      System.out.println("NOOO SCRIPT DOUBLE "+e);
    }

That is the error

javax.script.ScriptException: JavaScript implementation not found!

Desired behavior

To run Javascript code in Java without running any error. With all JDK 11 was easy with Nashorn. What is the “Nashorn of JDK 17”? Thanks a lot
Repl link:

code snippet

I would recommend just using:

import java.time.LocalDateTime;

LocalDateTime.getHours();

Rather than attempting to interpret JavaScript in Java.

3 Likes

Nashorn js was removed in Java 15,
but it appears to be active as standalone

alternatively there is Graal VM + Node.js. They can communicate to each other.

https://docs.oracle.com/en/graalvm/enterprise/20/docs/reference-manual/js/NashornMigrationGuide/