// Tomcat 重启动
try {
//1 获得Server
Class server = Class.forName("org.apache.catalina.ServerFactory");
Method getServer = server.getDeclaredMethod("getServer", new Class[0]);
Object obj = getServer.invoke(server, new Object[0]);
//2 获得Services
Method findServices = obj.getClass().getDeclaredMethod("findServices",new Class[0]);
Object[] objs = (Object[])findServices.invoke(obj, new Object[0]);
for (int i = 0; i < objs.length; i++) {
Method getContainer = objs[i].getClass().getMethod("getContainer", new Class[0]);
Object container = getContainer.invoke(objs[i], new Object[0]);
Method findChildren = container.getClass().getMethod("findChildren", new Class[0]);
Object[] containers = (Object[])findChildren.invoke(container, new Object[0]);
// 3.这里是要重启动的系统的名称如/systemXXX
Object[] objss = {"/xxxx"};
Class[] cls = {java.lang.String.class};
for (int j = 0; j < containers.length; j++) {
Method temp = containers[j].getClass().getMethod("findChild", cls);
Object abmApp = temp.invoke(containers[j], objss);
if (abmApp != null) {
//可以为stop,reload
Method relaod = abmApp.getClass().getMethod("reload", new Class[0]);
relaod.invoke(abmApp, new Object[0]);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
</script>