Reputation: 93
I have been trying to execute jar files. I first learnt how to execute them through cmd and I did fairly well. Now, I am currently trying to run the jar file from Java code that I have been writing. The jar is located in my machine and I run the jar through jar code as shown below:
Runtime r = Runtime.getRuntime();
Process p = null;
p = r.exec(new String[] { "cmd", "/c", "start C:\\jartest\\JavaApplication.jar" });
This works really good on my machine. The output of JavaApplication.jar is that it creates a folder and the output is achieved.
The problem occurs, when I want to run a Jar file located at Raspberry PI from my machine through Servlet. The code is as shown below:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
QLM qlm = new QLM();
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("Response of Servlet Content Started \n");
String message= request.getParameter("msg");
out.println(message);
if((qlm.get_Envelop(message))!= null){
out.println("DATA IS VALID");
} else out.println("WRONG MESSAGE!!");
out.println("Response of Servlet Content end \n");
**Runtime r = Runtime.getRuntime();
out.println("Am I here??");
r.exec(new String[] {"cmd","/c", "start /home/pi/JARTest/JavaApplication24.jar", "file1" });**
out.println("Did it work??");
} finally {
out.close();
}
}
It is the same jar file that was on my Machine. I put/store JavaApplication.jar on PI through WinSCP. The path where the jar located on Raspberry PI is: /home/pi/JARTest. I pass the command line argument as "file1" to the Jar file. The other operations of servlet works fine as well, except from running the Jar file.
P.S- The result of the jar (JavaApplication.jar) is same. It works on my machine (Windows), but it simply doesn't want to accept the same jar file and the same command Runtime r = Runtime.getRuntime(); on Raspberry PI.
Please help me with this. Any input/suggestions/ideas will be deeply appreciated.
Thanks in advance.
Upvotes: 0
Views: 652
Reputation: 262514
r.exec(new String[] {
"cmd","/c", "start /home/pi/JARTest/JavaApplication24.jar", "file1" });
That is Windows code. It calls "cmd", the Windows command shell. So that won't work on other OS (like the Linux on your Pi).
Try to rewrite it using the "java" command.
Upvotes: 1