Reputation: 3984
I want to run executable jar located in /WEB-INF/lib
from my java servlet
and get the output.
tried :
Process procesSH;
BuffererdReader br = null;
ProcessBuilder pb = new ProcessBuilder("/WEB-INF/lib/jarName.jar", "-jar", "parma01 parma02");
procesSH = pb.start(); // start pb
br = BuffererdReader(new InputStreamReader(procesSH.getInputStream()));
system.out.println(br.readLine()); // read just one line for now
The error I get is:
CreateProcess error = 2, system cannot find file specified.
The file is located under /WEB-INF/lib
, if there is more info needed I will post it.
Thanks.
Upvotes: 0
Views: 1528
Reputation: 32980
The path /WEB-INF/lib/jarName.jar
obviously did not work, here is a way to obtain an absolute path to the jar via the ServletContext
:
ServletContext context = ...
String jarpath = context.getRealPath("/WEB-INF/lib/jarName.jar");
ProcessBuilder pb = new ProcessBuilder(jarpath, "-jar", "parma01 parma02");
Upvotes: 1