This is because you probably loaded the script as a string. Most examples:
engine.eval(new FileReader("scripts/hello.js"));
, script, FileReader. engine.eval("print('hello')"), , .
script , jjs, .
Java, : js:
ScriptContext ctx = engine.getContext();
ctx.getBindings(ScriptContext.GLOBAL_SCOPE).put("thisFile", script);
engine.eval(new FileReader(script), defCtx);
js:
print("I am " + thisFile);
:
I am resources/test.js
. , jdk.nashorn.tools.Shell jdk.nashorn.internal.runtime.Context, .