简体   繁体   English

是否可以通过 Graal 从 JavaScript 调用 Kotlin?

[英]Is it possible to call Kotlin from JavaScript via Graal?

This works这有效

var NodeTransformerClass = Java.type('com.fispan.crypto.api.java.NodeTransformer');
var nodeTransformer = new NodeTransformerClass();
var result = nodeTransformer.protect(customer, specification);

but this但是这个

var KotlinTransformerClass = Java.type('com.fispan.crypto.api.kotlin.NodeTransformer');
var kotlinTransformer = new KotlinTransformerClass();
var kotlinResult = kotlinTransformer.protect(customer, specification);

produces产生

unknown:0
unknown
^

[Error: kotlin/jvm/internal/Intrinsics]

Am I correct in assuming there is no way to call Kotlin directly from JavaScript/Node/js?假设无法直接从 JavaScript/Node/js 调用 Kotlin,我是否正确?

Also if you call Node.js -> Java -> Kotlin, you get the same message.此外,如果您调用 Node.js -> Java -> Kotlin,您会得到相同的消息。

Am I correct in assuming there is no way to call into the JVM from Node.js if there is any Kotlin code in the call chain?如果调用链中有任何 Kotlin 代码,我是否正确地假设无法从 Node.js 调用 JVM? Would this also be true of Scala or any other JVM language?这也适用于 Scala 或任何其他 JVM 语言吗? 🤔 🤔

If so, this makes GraalVM completely unsuitable to our needs?如果是这样,这让 GraalVM 完全不适合我们的需求? 😥 😥

See also https://github.com/oracle/graaljs/issues/484另见https://github.com/oracle/graaljs/issues/484

Okay, finally figured this out... I did not have a complete JAR on my Graal Node classpath .好吧,终于想通了……我的 Graal Node classpath上没有完整的 JAR。 Java was working because the Java runtime is automatically included, but the Kotlin runtime is not. Java 可以工作,因为 Java 运行时会自动包含在内,但 Kotlin 运行时未包含在内。

My solution was to use the Gradle shadow plugin to build a complete JAR.我的解决方案是使用 Gradle shadow插件来构建一个完整的 JAR。 Once I did this, Node.js can call Java, and Java can call Kotlin.一旦我这样做了,Node.js 就可以调用 Java,而 Java 可以调用 Kotlin。

See also fat-JAR and uber-JAR另见 fat-JAR 和 uber-JAR

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM