我的想法是把weblogic安装为window的服务,然后通过“net”命令来启动或停止,而判断weblogic启动或停止的方法就是采用一个Socket连接过去,如果连接异常就表示没有启动。下面是我针对Mysql做类似的工作:public class RunCommand {
public static void main(String[] args) throws Exception {
boolean run = false;
try {
Socket socket = new Socket("localhost" , 3306);
run = socket.isConnected();
} catch (ConnectException e) {
System.out.println("Mysql has stop");
}
if (run) {
System.out.println("Mysql is running");
} else {
System.out.println("Start to MySQL");
Runtime runtime = Runtime.getRuntime();
Process p = runtime.exec("net start MySQL");
//p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = reader.readLine();
while(line!=null) {
System.out.println(line);
line=reader.readLine();
}
}
}
}