public static void main(String args[]) {
try {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("mvn -version");
InputStream stderr = proc.getErrorStream();
InputStreamReader isrerr = new InputStreamReader(stderr);
BufferedReader brerr = new BufferedReader(isrerr);
InputStream stdin = proc.getInputStream();
InputStreamReader isrin = new InputStreamReader(stdin);
BufferedReader brin = new BufferedReader(isrin);
String line = null;
while ((line = brerr.readLine()) != null)
System.out.println(line);
while ((line = brin.readLine()) != null)
System.out.println(line);
int exitVal = proc.waitFor();
} catch (Throwable t) {
t.printStackTrace();
}
}
this code doesn't work well,there isn't output,and the process can't stop.
help me!thank advance.I want to execute maven command in java program by invoking command line,but it output error:it will output error java.io.IOException: Cannot run program "mvn": but if i run the same command int the command line , it works well.