最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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
发布评论

评论列表(0)

  1. 暂无评论