importPackage
is originally from Rhino. Even Nashorn supports it when Rhino/Mozilla compatibility is requested explicitly using load("nashorn:mozilla_compat.js");
only, see Rhino Migration Guide in the documentation of Nashorn.
Graal.js has Nashorn compatibility mode and it supports load("nashorn:mozilla_compat.js");
in this mode.
So, you can use something like
System.setProperty("polyglot.js.nashorn-compat", "true");
ScriptEngine engine = new ScriptEngineManager().getEngineByName("graal.js");
System.out.println(engine.eval("load('nashorn:mozilla_compat.js'); importPackage('java.awt'); new Point();"));
(it prints java.awt.Point[x=0,y=0]
which shows that the package java.awt
was imported successfully).