Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
87
rated 0 times [  92] [ 5]  / answers: 1 / hits: 37144  / 12 Years ago, mon, october 15, 2012, 12:00:00

I tried to run a jar file on nodejs but it threw out a following error:



Error: Unable to access jarfile /home/example/Applications/example.jar


This is the following code that I have in my test.js:



var exec = require('child_process').exec, child;
child = exec('/usr/bin/java -jar ~/Applications/example.jar',
function (error, stdout, stderr){
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if(error !== null){
console.log('exec error: ' + error);
}
});


I ran my test.js with nodejs in this command but received the error above:



node test.js


Is there any mistake that I made with my code? I am not sure why it is throwing an error at this point.


More From » java

 Answers
22

remove .jar from exec();



java will find the jar file without .jar when using the -jar argument. else its like.. searching for filename.jar.jar



special snowflake macos requires the .jar and does not work if you omit it.

(thanks to Gʀɪᴍ) he also created a related question


[#82550] Friday, October 12, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
damiondenzelc

Total Points: 268
Total Questions: 116
Total Answers: 116

Location: North Korea
Member since Tue, Jun 16, 2020
4 Years ago
;