javascript - Call to node js application inside java project -
i've create new java project following code open command line project path.in java project i've added 2 files(under root) app.js , package json,now want invoke node app.js
i use following code open command line working ok
process newproc = runtime.getruntime().exec("cmd /c start cmd.exe"); outputstream out = newproc.getoutputstream();
if put in command line manually(which opened above program): node app.js the node js starting ok. want of java code like
runtime.getruntime().exec("cmd /c start cmd.exe node app.js");
and either runtime.getruntime().exec("node app.js");
when try not working...
my java project followoing
myproj src web app.js package.json
update this app.js file
var express = require('express'); var app = express(); app.get('/', function (req, res) { res.send("test app running"); }); var server = app.listen(3005, function () { console.log("listen" + 3005) } )
try processbuilder
instead of runtime
:
processbuilder pbuilder = new processbuilder("c:\\program files\\nodejs\\node.exe", "c:\\temp\\app.js"); process process = pbuilder.start(); process.waitfor();
Comments
Post a Comment