Hello all,
I see there are JMX APIs to get the web applications currently deployed in
Tomcat.
However, I see that even if the applications are failed to deploy, they still
get listed. Is there any way to get ONLY deployed and RUNNING applications ?
Below is sample snippet which gives all the currently deployed apps ..even if
there are some apps which had errors and thus failed to deploy:
public List<String> collectAllDeployedApps() throws
MalformedObjectNameException, AttributeNotFoundException,
InstanceNotFoundException, MBeanException, ReflectionException {
List<String> webappNames = new ArrayList<>();
List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null);
for (MBeanServer server : servers ) {
Set<ObjectName> names = server.queryNames(new
ObjectName("Catalina:type=Host,*"), null);
Set<String> hostNames = new HashSet<String>();
for (ObjectName on : names) {
hostNames.add(on.getKeyProperty("host"));
}
for (String str : hostNames) {
ObjectName[] webapps = (ObjectName[]) server
.getAttribute(new ObjectName("Catalina:type=Host,host=" + str), "children");
for (ObjectName ob : webapps) {
String[] appSpl = ob.getKeyProperty("name").split("//localhost");
System.out.println(ob.getKeyPropertyList());
webappNames.add(appSpl[1]);
}
}
}
return webappNames;
}
}