Search code examples
jbossjboss7.xjmxillegalstateexceptionmbeans

JBoss 7.1: java.lang.IllegalStateException: No 'jboss' MBeanServer found


My application is deployed on JBoss 7.1 (standalone). I am getting an exception on the following line:

MBeanServerConnection server = MBeanServerLocator.locateJBoss();

The exception is:

JBoss: java.lang.IllegalStateException: No 'jboss' MBeanServer found!

That code above worked fine when the app was deployed on JBoss 5.

From what I was reading online, the code is supposed to work only when it's called from the same JVM in which the MBeanServer was created. Otherwise it's a remote call and I have to use JNDI. But is it not a local call (same JVM - i.e. the JBoss JVM)? How did it work on JBoss 5 then? How do I make it work on JBoss 7.1 standalone, without changing this specific code?


Solution

  • Here is the solution:

    https://community.jboss.org/thread/221708

    Quote:

    Above problem is dueto locateJboss implementation that is compatible with older version of Jboss. The MBeanServer used by JBoss 7 (by default) is the platform MBeanServer. The class name iscom.sun.jmx.mbeanserver.JmxMBeanServer and the default domain is DefaultDomain. Accordingly, you can simply use:

    java.lang.management.ManagementFactory.getPlatformMBeanServer()
    

    Alternatively:

     for(MBeanServer server: javax.management.MBeanServerFactory.findMBeanServer(null)) {
    
          if("DefaultDomain".equals(server.getDefaultDomain())) return server;
    
     }
    
     throw new Exception("Failed to locate MBeanServer");
    

    On another note, jboss.system:type=ServerInfo object name doesn't work in AS 7.1 I had to use JVM specific parameters to nail down to MBean attributes. 'java.lang:type=Memory' and attribute as 'HeapMemoryUsage'.