我可以通过 JNI 从 Node.js 调用 Java 吗?如何? [英] Can I call Java from Node.js via JNI and how?

查看:23
本文介绍了我可以通过 JNI 从 Node.js 调用 Java 吗?如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过 JNI 从 Node.js 调用 Java 吗?有例子吗?

can I call Java from Node.js via JNI? Are there any examples?

推荐答案

这看起来很棘手.Node.JS 在 Google Chrome JavaScript 引擎 V8 上运行.您需要做的是创建一个 V8 C++ 绑定(v8 c++ Crash Course显示了一个示例),它启动一个 JVM 并执行所有 JNI 处理.

That looks tricky. Node.JS runs on the Google Chrome JavaScript engine V8. What you will have to do is to create a V8 C++ binding (v8 c++ Crash Course shows an example) that starts a JVM and does all the JNI handling.

我认为让 JavaServer 和 Node.js 通过网络进行通信可能会更好(有人写了 使用 RabbitMQ 进行基于 Java/Node.js 消息的通信的示例).在这里,JSON 将是一种很好的数据交换格式(如果你相信你的 Java 服务器会生成正确的 JSON,你可以在 Node 中 eval() 它).

I think you might be better off letting a JavaServer and Node.js communicate via the network (someone wrote an example for using RabbitMQ for Java/Node.js message based communication). Here, JSON would be a great data exchange format (if you trust your Java server produces proper JSON you can just eval() it in Node).

这篇关于我可以通过 JNI 从 Node.js 调用 Java 吗?如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆