我正在構建一個Java程序,用於在我的服務器端自動執行一個過程。通常,我cd到Desktop/GIT /並使用這個maven命令「mvn integration-test -DskipTests -P interactive -e」。如何從java程序運行mvn命令?
我正在構建一個java程序,我試圖運行那個命令行,但到目前爲止我還沒有成功。
到目前爲止,這裏是代碼:
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
Process theProcess = null;
try
{
theProcess = Runtime.getRuntime().exec("mvn integration-test -DskipTests -P interactive -e");
}
catch(IOException e)
{
System.err.println("Error on exec() method");
e.printStackTrace();
}
// read from the called program's standard output stream
try
{
inStream = new BufferedReader(new InputStreamReader(theProcess.getInputStream()));
System.out.println(inStream.readLine());
}
catch(IOException e)
{
System.err.println("Error on inStream.readLine()");
e.printStackTrace();
}
break;
}
}
in.close();
}
感謝您的快速回答,我想了解那裏的例子,但我無法確定在哪裏放置代碼行「mvn integration-test -DskipTests -P interactive -e」。有什麼想法嗎? – 2012-04-25 11:58:54