Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a jar file in node js application

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.

like image 882
user7350714 Avatar asked Sep 13 '25 02:09

user7350714


1 Answers

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 com.foo.MyMainClass
like image 158
lance-java Avatar answered Sep 14 '25 16:09

lance-java