从 java 内部调用 node.js 脚本

Calling a node.js script from inside java(从 java 内部调用 node.js 脚本)
本文介绍了从 java 内部调用 node.js 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

如何在 java 中调用 node.js 并将 console.log 值保存在 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 应用可以使用的 rest 服务.

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-java 之类的东西从 Node.JS 应用程序调用 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 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)