Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Correct markup

...

  1. Start your Tomcat and check that you have access to http://localhost:8080/manager/jmxproxy/. It means that JMX is enabled on your Tomcat configuration (if not, check if the following line is in your /conf/server.xml file : <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />. Otherwise, check the Tomcat documentation to activate it). Let this page opened to check further if your custom Mbean is detected by Tomcat.

...

Here is a capture of the println() : https://picasaweb.google.com/lh/photo/jzVX9-NBGwF57A0m8qqv2Q?feat=directlink. Tomcat seems to register 2 2nd Mbean server but when I try to fetch mine from its AgentId (here "myMBServer"), nothing is found. In my opinion, Tomcat might re-implement the MBeanServerFactory java class to control the server creation. Then, it doesn't keep a reference to the newly created MBean server. Moreover, if Tomcat re-implement the MBeanFactory class, there is no method to directly add MBean (see the http://tomcat.apache.org/tomcat-6.0-doc/api/index.html).

...

3. Build your ContextListener : According to the [Tomcat's documentation|[http://tomcat.apache.org/tomcat-6.0-doc/config/listeners.html, a Listener is a a component that performs actions when specific events occur, usually Tomcat starting or Tomcat stopping.. We need to instantiate and load our MBean at Tomcat's start. So we build a ContextListener.java file which is placed wherever you want in your project architecture :

...

In his tutorial, Christopher Blunck suggests to compile the ContextListener.java file in a jar archive and then place it into our WEB-INF/lib folder. In my own experiments, I never found any difference without doing this.

...

  1. Build your MBean,
    b. Compile it and place the .jar archive in the Tomcat's /lib folder,
    c. Build your ContextListener.java,
    d. Add a reference to your ContextListener inside your WEB-INF/web.xml file,

...

Do not hesitate to check the ManagementFactory class javadoc.

...

CategoryFAQ