如何使用node.js child_process API运行jar文件? [英] How to run a jar file with node.js child_process API?

查看:194
本文介绍了如何使用node.js child_process API运行jar文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在nodejs上运行一个jar文件,但它抛出了以下错误:

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

这是我在测试中的以下代码.js:

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);
    }
});

我在此命令中使用nodejs运行了我的test.js,但收到了上述错误:

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.

推荐答案

删除 .jar 来自 exec();

java将找到没有 .jar 使用 -jar 参数时。其他就像..搜索 filename.jar.jar

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

这篇关于如何使用node.js child_process API运行jar文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆