Hi,
I am trying to write a MBean using the Modeler API in tomcat. The details
of my environment are as below:-
Tomcat version : 7.0.54
JDK version : 1.7
OS : windows 7
The MBean written using Modeler API is not getting deployed and hence not
showing up on JConsole.
Following is the simple MBean code which has been written with its
mbeans-descriptors.xml
HelloMBean.java
-------------------------
package com.example.mbean;
public interface HelloMBean {
void sayHello();
}
Hello.java
---------------------------
package com.example.mbean;
import javax.management.MBeanException;
import javax.management.RuntimeOperationsException;
import org.apache.catalina.mbeans.MBeanUtils;
import org.apache.tomcat.util.modeler.BaseModelMBean;
import org.apache.tomcat.util.modeler.ManagedBean;
import org.apache.tomcat.util.modeler.Registry;
public class Hello extends BaseModelMBean implements HelloMBean {
protected Registry registry = MBeanUtils.createRegistry();
protected ManagedBean managed = registry.findManagedBean("Custom");
protected Hello() throws MBeanException, RuntimeOperationsException {
super();
}
@Override
public void sayHello() {
System.out.println("sayHello()");
}
}
mbeans-descriptors.xml
------------------------------
<?xml version="1.0"?>
<mbeans-descriptors>
<mbean name="Custom"
className="com.example.mbean.Hello"
description="Custom Hello"
domain="Catalina"
group="Custom"
type="com.example.mbean.HelloMBean">
<operation name="sayHello"
description="Saying Hello"
impact="ACTION" returnType="void">
</operation>
</mbean>
</mbeans-descriptors>
All the above files are in the same package and bundled as jar. I have
tried placing this jar in server\lib directory as well as in a webapp.
Sadly there is very little documentation on how to go about writing a MBean
using this API.
Any help on this would be greatly appreciated.
Thank You!
Regards,
-Yogesh