How to Shutdown JBoss AS 7 with JMX Remoting

import java.io.IOException;

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();

      conn.invoke(new ObjectName("jboss.as:management-root=server"), "shutdown", null, null);
    } 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