I'm trying to run a jar file "reportTool.jar" from another java application using the lang.Process class.
...
String os = System.getProperty("os.name").toLowerCase();
String shell = "";
if (os.contains("win")) shell = "cmd";
else shell = "/bin/sh";
logger.info(shell);
Process process = Runtime.getRuntime().exec(shell + " java -jar " + reportToolJar);
logger.info("Waiting for reportTool");
InputStream in = process.getInputStream();
InputStream err = process.getErrorStream();
BufferedReader brIN = new BufferedReader(new InputStreamReader(in), 999999);
BufferedReader brERR = new BufferedReader(new InputStreamReader(err), 999999);
String lineERR, lineIN;
while ((lineERR = brERR.readLine()) != null) {
logger.error(lineERR);
}
brERR.close();
while ((lineIN = brIN.readLine()) != null) {
logger.info(lineIN);
}
brIN.close();
process.waitFor();
...
However, when I go to execute I get
411 [main] ERROR reportToolController.ReportToolController - /usr/bin/java: /usr/bin/java: cannot execute binary file
To note, reportToolJar is a String holding the absolute path to the jar file, this path is correct.
reportToolJar runs fine when being run from Terminal using the very same command that is executed in the code above.
echo $SHELL? Then can you try the same java code with that shell instead of/bin/sh?