Jor*_*Jor 8 java grails groovy node.js
有人试过如何从java或groovy运行node.js模块或脚本?
可以groovy command.execute()吗?如果是这样,那么它将在不同的操作系统中表现相同.
值得注意的是,理想情况下,我希望node.js不会依赖于在system和node命令中的安装,而是通过./configure和make打包,以便它可以用作库.
谢谢
编辑:基本上我想要这个,这样我就可以使用node.js模块,一个客户端框架(咖啡脚本,玉器,手写笔等等,这是Brunch中的Bundeled),作为Grails插件.这样插件是自包含的,没有系统依赖性.
从网站:
什么是vert.x?
下一代多语言异步应用程序框架.(以前称为node.x)
是的,你可以直接 command.execute()
一种更优雅的方法可能是构建一个仅接受来自本地主机的请求的小型 node.js 服务器。但是这个 groovy 有效:
def file = new File("script.js")
def fileStream = file.newOutputStream()
fileStream << "console.log('hello from node.js');"
fileStream.close()
def command = "/usr/local/bin/node " + file.absolutePath
def proc = command.execute()
proc.waitFor()
println "return code: ${ proc.exitValue()}"
println "stderr: ${proc.err.text}"
println "stdout: ${proc.in.text}"
Run Code Online (Sandbox Code Playgroud)