Something strange happens when I try running a java -jar
command programatically on Windows.
When running the command like this:
Process p = Runtime.getRuntime().exec(cmd); //cmd string is ok
p.waitFor();
I get the error
Error: Could not find or load main class �jar
The cmd
var is constructed like this:
cmd = String.format("java –jar %s –o win -i %s -n %s -d %s -s %s", jarLocation, param1, param2, tgtFilePath, srcFilePath);
I tried debugging this issue so I copy pasted the command to CMD and got the same error. However, when I typed it manually and not copy pasted, everything just worked fine.
When getting the bytes of each String I got:
bytes of generated string:
[106, 97, 118, 97, 32, -30, -128, -109, 106, 97, 114, 32, 110, 112, 116, 95, 108, 105, 99, 101, 110, 115, 101, 46, 106, 97, 114, 32, -30, -128, -109, 111, 32, 119, 105, 110, 32, 45, 105, 32, 104, 111, 115, 116, 105, 100, 55, 56, 57, 48, 49, 32, 45, 110, 32, 104, 111, 115, 116, 110, 97, 109, 101, 32, 45, 100, 32, 108, 105, 99, 101, 110, 99, 101, 70, 105, 108, 101, 45, 105, 110, 112, 117, 116, 76, 105, 99, 101, 110, 99, 101, 45, 114, 101, 115, 117, 108, 116, 46, 100, 97, 116, 32, 45, 115, 32, 108, 105, 99, 101, 110, 99, 101, 70, 105, 108, 101, 45, 105, 110, 112, 117, 116, 76, 105, 99, 101, 110, 99, 101]
bytes of hard coded string:
[106, 97, 118, 97, 32, 45, 106, 97, 114, 32, 110, 112, 116, 95, 108, 105, 99, 101, 110, 115, 101, 46, 106, 97, 114, 32, 45, 111, 32, 119, 105, 110, 32, 45, 105, 32, 104, 111, 115, 116, 105, 100, 55, 56, 57, 48, 49, 32, 45, 110, 32, 104, 111, 115, 116, 110, 97, 109, 101, 32, 45, 100, 32, 108, 105, 99, 101, 110, 99, 101, 70, 105, 108, 101, 45, 105, 110, 112, 117, 116, 76, 105, 99, 101, 110, 99, 101, 45, 114, 101, 115, 117, 108, 116, 46, 100, 97, 116, 32, 45, 115, 32, 108, 105, 99, 101, 110, 99, 101, 70, 105, 108, 101, 45, 105, 110, 112, 117, 116, 76, 105, 99, 101, 110, 99, 101]
The jarLocation is the one parameter that is already hard coded and not received as a web service parameter.
What can cause an issue like that?
when I typed it manually and not copy pasted, everything just worked fine
means? – Naman Gala