I'd like to check status and start/stop deployments of a web app programatically in JBoss as 7.2.0Final. I've found that for status it can be done using MBean like that, but i don't know if it's the best way to do it:
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName myApp= new ObjectName("jboss.as:deployment=myApp.war");
String deploymentStatus = server.getAttribute(myApp, "status").toString();
Any idea about how to start and stop deployment?
Finally, I was able to answer my question, I share my solution, it may be helpful: - Start deployment:
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName obj= null;
try {
obj= new ObjectName("jboss.as:deployment=my_war.war");
server.invoke(obj, "deploy", null, null);
} catch (InstanceNotFoundException | ReflectionException | MBeanException | MalformedObjectNameException e) {
//Log error
}
- To stop deployment, use "undeploy" instead of "deploy" in invoke method.