private static void maybeStartHtmlJmxAdaptor() {
    MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();

    String htmlAdaptorAvailable = System.getProperty("hornetq.htmladaptor.available");

    if ("TRUE".equalsIgnoreCase(htmlAdaptorAvailable)) {

      try {

        String strPort = System.getProperty("hornetq.htmladaptor.port");

        int htmlAdaptorPort = Integer.parseInt(strPort);

        String userName = System.getProperty("hornetq.htmladaptor.userName");
        String password = System.getProperty("hornetq.htmladaptor.password");

        final HtmlAdaptorServer adapter = new HtmlAdaptorServer();

        ObjectName adapterName =
            new ObjectName("SimpleAgent:name=htmladapter,port=" + htmlAdaptorPort);

        adapter.setPort(htmlAdaptorPort);

        if (userName != null && password != null) {
          adapter.addUserAuthenticationInfo(new AuthInfo(userName, password));
        }

        beanServer.registerMBean(adapter, adapterName);
        adapter.start();

        Runtime.getRuntime()
            .addShutdownHook(
                new Thread() {
                  public void run() {
                    adapter.stop();
                  }
                });
      } catch (Exception e) {
        log.error("Error starting up the HtmlAdaptorServer: " + e.getMessage(), e);
        log.error(
            "If you don't want this, remove the hornetq.htmladaptor.available property "
                + "or set it to false");
        System.exit(-1);
      }
    }
  }
  public static void main(String[] args) throws Exception {
    MBeanServer server = MBeanServerFactory.createMBeanServer();

    ObjectName helloName = new ObjectName("Hello:name=HelloWorld");
    server.registerMBean(new Hello(), helloName);

    ObjectName adapterName = new ObjectName("HelloAgent:name=htmladapter,port=8082");
    HtmlAdaptorServer adapter = new HtmlAdaptorServer();
    server.registerMBean(adapter, adapterName);

    adapter.start();
    System.out.println("start.....");

    int rmiPort = 1099;
    String jmxServerName = "TestJMXServer";
    JMXServiceURL url =
        new JMXServiceURL(
            "service:jmx:rmi:///jndi/rmi://localhost:" + rmiPort + "/" + jmxServerName);
    System.out.println("JMXServiceURL: " + url.toString());
    JMXConnectorServer jmxConnServer =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);
    jmxConnServer.start();
  }