2015-10-21 61 views
1

有沒有辦法讓使用JMX(ServerMBean)或JNDI在Java中實現的Jboss 6.0 上的所有部署列表?使用JMX或JNDI列出來自Jboss的所有部署

+0

使用'jconsole'如果你發現有一個操作返回部署 - >是的,有一種方法可以通過JMX獲取它,否則不是。如何使用'jboss-cli'來處理這類信息? – SubOptimal

+0

我需要在Java的代碼這一點,但我不能找出的ObjectName或所得的Bean類是什麼 – FrederikH

+0

希望這可能是在 '設置的MBeans = ManagementFactory.getPlatformMBeanServer()的形式。queryMBeans(新的ObjectName(「org.jboss.admin:type = Application,name = *」),null); (ObjectInstance objectInstance:mBeans){ \t \t services.add(JMX.newMXBeanProxy(server,objectInstance.getObjectName(),ApplicationMXBean.class)); \t}' – FrederikH

回答

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