我正在尝试使用 graal + nashorn interop 来编写与 Java 交互的 nodejs。我从 graal 开始node --jvm --jvm.Xss2m --jvm.Dtruffle.js.NashornJavaInterop=true --jvm.classpath=libs/ --polyglot app.js
。我不能扩展一个类。javascript代码是
const GraaljsgrpcServiceImpl = Java.type('com.thing.GraaljsgrpcServiceImpl');
const HelloReply = Java.type('com.thing.HelloReply');
var GrpcImpl = Java.extend(GraaljsgrpcServiceImpl, {
sayHello: function(request, responseObserver) {
responseObserver.onNext(HelloReply.newBuilder().setMessage("Hello " + request.getName()).build());
responseObserver.onCompleted();
}
});
我的错误是
TypeError: Could not determine a class loader with access to the JS engine and class com.thing.GraaljsgrpcServiceImpl
这似乎指向我引用的java代码的类加载器问题以及javascript运行的位置(即2个不同的类加载器)。使用 graal/nodejs 时有没有办法解决这个问题?