javascript - How to execute a jar file in node js application - Stack Overflow

I had a node js application and I want to execute a very basic jar file which has System.out.println(&q

I had a node js application and I want to execute a very basic jar file which has System.out.println("Hello"); So that I need to capture that result in one variable.How can we do this. I tried this

var exec = require('child_process').exec;
var child = exec('java -jar ./TestFile.jar',
function (error, stdout, stderr){
console.log('Output -> ' + stdout);
if(error !== null){
  console.log("Error -> "+error);
}
});
module.exports = child;

But it is giving me error as

Output ->
Error -> Error: Command failed: C:\windows\system32\cmd.exe /s /c "java -jar ./TestFile.jar"
no main manifest attribute, in ./TestFile.jar

Can someone help how can we run this jar file so that I can display that result on my client side.

I had a node js application and I want to execute a very basic jar file which has System.out.println("Hello"); So that I need to capture that result in one variable.How can we do this. I tried this

var exec = require('child_process').exec;
var child = exec('java -jar ./TestFile.jar',
function (error, stdout, stderr){
console.log('Output -> ' + stdout);
if(error !== null){
  console.log("Error -> "+error);
}
});
module.exports = child;

But it is giving me error as

Output ->
Error -> Error: Command failed: C:\windows\system32\cmd.exe /s /c "java -jar ./TestFile.jar"
no main manifest attribute, in ./TestFile.jar

Can someone help how can we run this jar file so that I can display that result on my client side.

Share Improve this question edited Oct 15, 2018 at 17:03 Cœur 38.8k25 gold badges205 silver badges277 bronze badges asked Mar 15, 2017 at 13:36 user7350714user7350714 3652 gold badges6 silver badges23 bronze badges 1
  • That looks like an issue with the JAR manifest rather than your Node code. Have you tried running java -jar ./TestFile.jar manually? – Joe Clay Commented Mar 15, 2017 at 13:37
Add a ment  | 

1 Answer 1

Reset to default 4

You obviously haven't specified a Main-Class in your jar's manifest so you can't run it via java -jar. See here for more info.

If not using a Main-Class entry in your jar's manifest, you'll need to run via

java -cp ./TestFile.jar .foo.MyMainClass

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744554108a4580477.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信