How do I access the MBeanServer or MBeanServerConnection from inside JBoss EAP

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 4.x
    • 5.x
    • 6.x
    • 7.x

Issue

Resolution

  • EAP 4.x, 5.x

    import org.jboss.mx.util.MBeanServerLocator;
    import javax.management.MBeanServerConnection;
    ...
    MBeanServerConnection server = MBeanServerLocator.locateJBoss();
    

    Note: The MBeanServerLocator class is located in $JBOSS_HOME/client/jboss-j2se.jar in EAP 5.x, and in $JBOSS_HOME/client/jmx-client.jar (or $JBOSS_HOME/client/jbossall-client.jar) in EAP 4.x.

  • EAP 6.x, 7.x

    import java.lang.management.ManagementFactory;
    import javax.management.MBeanServer;
    ...
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    
Components

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.