使用JMX或JNDI列出Jboss的所有部署

时间:2015-10-21 11:01:16

标签: java jboss jndi jmx

有没有办法在Jboss 6.0上获取所有部署的列表 使用JMX(ServerMBean)或JNDI?

在Java中实现

1 个答案:

答案 0 :(得分:0)

在Wildfly 9.0.1.Final上,代码如下所示:

    String host = "localhost";
    int port = 9990;
    String urlString = System.getProperty("jmx.service.url","service:jmx:http-remoting-jmx://" + host + ":" + port);
    JMXServiceURL serviceURL = new JMXServiceURL(urlString);
    JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
    MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
    ObjectName name = new ObjectName("jboss.modules:type=ModuleLoader,name=*");
    Set<ObjectInstance> objectInstances = connection.queryMBeans(name, null);
    for (ObjectInstance objectInstance : objectInstances) {
        if (objectInstance.getObjectName().getCanonicalName().contains("ServiceModuleLoader")) {
            System.out.println("invoking method on " + objectInstance.getObjectName());
            Object dumpAllModuleInformation = connection.invoke(objectInstance.getObjectName(), "dumpAllModuleInformation", new Object[]{}, new String[]{});
            System.out.println(dumpAllModuleInformation);
        }
    }
    jmxConnector.close();

也许你可以将它改编为JBoss 6.在Wildfly 9.0.1.Finale上输出:

Module deployment.stackoverflow-jboss-1.0-SNAPSHOT.war:main
    Class loader: ModuleClassLoader for Module "deployment.stackoverflow-jboss-1.0-SNAPSHOT.war:main" from Service Module Loader
    Resource Loaders:
        Loader Type: org.jboss.as.server.deployment.module.VFSResourceLoader
        Paths:

            META-INF
            META-INF/maven
            META-INF/maven/stackoverflow-jboss