Java代码:
Protocol 'Store' can only be used as a generic constraint because it has Self or associated type requirements
JavaScript代码:
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
public class WebCryptoInvoke {
public static void main(String[] args) throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
if (!(engine instanceof Invocable)) {
System.out.println("Invoking methods is not supported.");
return;
}
Invocable inv = (Invocable) engine;
String scriptPath = "/home/rajasekhar/Desktop/webcrypto.js";
engine.eval("load('" + scriptPath + "')");
Object webCrypto = engine.get("webcrypto");
Object result = inv.invokeMethod(webCrypto, "generateKeyPair");
System.out.println(result);
}
}
错误:
线程中的异常" main" javax.script.ScriptException: ReferenceError:" window"没有定义 /home/rajasekhar/Desktop/webcrypto.js在第9行 jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:470) 在 jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:392) 在 jdk.nashorn.api.scripting.NashornScriptEngine.invokeMethod(NashornScriptEngine.java:199) 在WebCryptoInvoke.main(WebCryptoInvoke.java:20)引起: /home/rajasekhar/Desktop/webcrypto.js:9 ReferenceError:" window"是 未定义于 jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)at at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319) 在 jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291) 在 jdk.nashorn.internal.objects.Global。的 noSuchProperty (Global.java:1441) 在 jdk.nashorn.internal.scripts.Script $重新编译$ 2 $ $ 86 webcrypto.generateKeyPair(/home/rajasekhar/Desktop/webcrypto.js:9) 在 jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637) 在 jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) 在 jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) 在 jdk.nashorn.api.scripting.ScriptObjectMirror.callMember(ScriptObjectMirror.java:199) 在 jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:386) ......还有2个