Call java program from Node.js application

后端 未结 5 1487
萌比男神i
萌比男神i 2020-12-16 03:37

From what I read, there are a couple of ways to run java files in a node.js application. One way is to spawn a child process: (the java code is pac

5条回答
  •  一整个雨季
    2020-12-16 03:43

    We can run the whole java project by making .jar file of it and run it using the command in the shell and run that shell file. In order to run java code from nodejs project as we know project could be a mix of java, js modules. Call exec() function in node to create a child process to execute the shell file having a command to run .sh file and can also pass some argument in it from use.eg;

    let fileName = 'someFile.txt';
    let userName = 'Charlie Angle'; 
    exec(`sh run.sh --context_param
    paramFilePath="./storage/${fileName}" --context_param userName="${userName}"`, (error, stdout, stderr) => {// Some code based on execution of above command})
    

提交回复
热议问题