Thursday, May 6, 2010

How to run command on Karaf command prompt from other java program

I wanted to uninstall 'clock_3.0' bundle which is running in karaf. So I can do it by typing 'features:uninstall clock_3.0' command on karaf command prompt.
But Now I wanted to run this command from some other Java program.

We can do this by running following command:

Process ls_proc1;
ls_proc1 = Runtime.getRuntime().exec("cmd.exe /C java -jar C:\\apache-felix-karaf-1.2.0\\lib\\karaf-client.jar features:uninstall clock_3.0");

where apache-felix-karaf-1.2.0 is installed at C: on my computer.

We can even display the output of this command:

try {
BufferedReader br = new BufferedReader(new InputStreamReader(ls_in));
while ((ls_str1 = br.readLine()) != null) {
System.out.println(ls_str1);
}
} catch (IOException e1) {
e1.printStackTrace();
}