private void doMain(String[] args) throws Exception { // create the object we will be exposing with JMX RuntimeCounter counter = new RuntimeCounter(); // create a new JMX server listening on a specific port JmxServer jmxServer = new JmxServer(JMX_PORT); try { // start our server jmxServer.start(); // register our object using the PublishAllBeanWrapper to expose the public fields and methods jmxServer.register( new PublishAllBeanWrapper( counter, new JmxResourceInfo("com.j256", null, "runtime counter"))); // we just sleep forever to let the jmx server do its stuff System.out.println("Sleeping for a while to let the server do its stuff"); System.out.println("JMX server on port " + JMX_PORT); Thread.sleep(1000000000); } finally { // unregister is not necessary if we are stopping the server jmxServer.unregister(counter); // stop our server jmxServer.stop(); } }