How to List MBeans in JBoss AS 7 with JMX Remoting

import static java.lang.System.out;

import java.io.IOException;
import java.util.Set;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

public final class JmxSample {

  public static void main(final String[] args) {
    JMXConnector connector = null;

    try {
      final JMXServiceURL url = new JMXServiceURL("service:jmx:remoting-jmx://localhost:9999"); // for stand-alone mode, the port is 4447 with an offset of 150 by server for domain mode

      connector = JMXConnectorFactory.connect(url); // authentication is disabled by default

      final MBeanServerConnection conn = connector.getMBeanServerConnection();

      final Set<ObjectName> names = conn.queryNames(null, null);

      for (final ObjectName name : names)
        out.println(name);

    } catch (final Exception e) {
      e.printStackTrace();
    } finally {

      if (connector != null) {

        try {
          connector.close();
        } catch (final IOException e) {
          e.printStackTrace();
        }

      }

    }

  }

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s