Tomcat Custom MBean

jmxtomcat

Does anyone know how to deploy a custom MBean to Tomcat?

So far I`ve found this http://www.junlu.com/list/3/8871.html. I copied my jar with my MBean to Tomcat lib directory so the Custom class loader should pick it up. I then followed the instructions but I kept getting the exception below. My MBean does definitely have a public constructor. If I removed the jar from the tomcat lib directory I get the same message which suggests its not picking up my jar or my jar is being loaded after the Apache MBean Modeler is running in Tomcat.

06-Aug-2010 12:14:23 org.apache.tomcat.util.modeler.modules.MbeansSource execute
SEVERE: Error creating mbean Bean:type=Bean
javax.management.NotCompliantMBeanException: MBean class must have public constructor
at com.sun.jmx.mbeanserver.Introspector.testCreation(Introspector.java:127)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(DefaultMBeanServerInterceptor.java:2
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(DefaultMBeanServerInterceptor.java:1
at com.sun.jmx.mbeanserver.JmxMBeanServer.createMBean(JmxMBeanServer.java:393)
at org.apache.tomcat.util.modeler.modules.MbeansSource.execute(MbeansSource.java:207)
at org.apache.tomcat.util.modeler.modules.MbeansSource.load(MbeansSource.java:137)
at org.apache.catalina.core.StandardEngine.readEngineMbeans(StandardEngine.java:517)
at org.apache.catalina.core.StandardEngine.init(StandardEngine.java:321)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:411)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

Best Answer

In my tests, this message appeared when class name and the name attribute in the mbeans-descriptors.xml file didn't match.

<mbeans-descriptors>
<mbean name="<your class name here>"
...

It seems tomcat is searching the constructor by the name attribute.