从java里面调用node.js脚本 [英] Calling a node.js script from inside java
问题描述
如何在java中调用node.js并将其保存在String变量中?
How can I call a node.js inside java and save the console.log values in a String variable?
推荐答案
Java应用程序可以与运行的Node.JS应用程序通信。例如,您可以让Node.JS应用程序在可用端口上运行,Java应用程序可以通过tcp套接字与其通信。
It is possible for a Java application to communicate with a running Node.JS application. For instance, you can have a Node.JS app running on an available port and the Java app can communicate with it via tcp sockets.
http://nodejs.org/api/net.html
或者,您可以创建http服务器并公开Java应用程序可以使用的休息服务。
Or you can create an http server and expose a rest service which your Java app can consume.
http://nodejs.org/api/http.html
或者如md_5所述,您可以使用Runtime .exec,然后在结果进程上调用getInputStream。
Or as md_5 says, you can use Runtime.exec and then call getInputStream on the resulting process.
http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html
您可以在node.js和Java之间进行通信的方式与可以进行的其他跨应用程序通信没有什么不同。
The ways you can communicate between node.js and Java are no different from other cross application communication that can be done.
从Node.JS应用程序使用像node-java这样的东西调用Java代码。
It is also possible to invoke Java code from your Node.JS application using something like node-java.
https://github.com/nearinfinity/ node-java
这篇关于从java里面调用node.js脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!