How to List Deployments in JBoss AS 5 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:rmi://localhost/jndi/rmi://localhost:1090/jmxconnector");

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

      final MBeanServerConnection conn = connector.getMBeanServerConnection();

      final Set<ObjectName> names = conn.queryNames(new ObjectName("jboss.management.local:j2eeType=J2EEApplication"), null);

      for (final ObjectName name : names)
        out.println(name.getKeyProperty("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