请问如何用JMX控制Servlet(非Servlet容器)。附出错程序,谢谢

05-09-06 jcylinder
想用JMX控制具体的Tomcat Servlet,而不是像一般讨论的控制Servlet容器。

首先实现Servlet

public class TestServlet extends HttpServlet implements TestBean{

public int getCount(){

return count;

}

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

......

}

}

TestBean如下定义:

public interface TestBean {

public int getCount();

}

Server类实现具体控制(目前仅为读取属性值)

public class Server {

public static void main(String[] args) {

......

mbs.createMBean("TestServlet", mbeanObjectName);

......

}

}

但是,执行时候出错:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/http/Ht

tpServlet

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(Unknown Source)

at java.security.SecureClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.access$100(Unknown Source)

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Unknown Source)

at com.sun.jmx.mbeanserver.ClassLoaderRepositorySupport.loadClass(Unknow

n Source)

at com.sun.jmx.mbeanserver.ClassLoaderRepositorySupport.loadClass(Unknow

n Source)

at com.sun.jmx.mbeanserver.MBeanInstantiatorImpl.findClassWithDefaultLoa

derRepository(Unknown Source)

at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(Unk

nown Source)

at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(Unk

nown Source)

at com.sun.jmx.mbeanserver.JmxMBeanServer.createMBean(Unknown Source)

at Server.createTestMBean(Server.java:83)

at Server.main(Server.java:36)

程序流程上是一定没有错的,因为CreateMBean的参数换成别的类名,可以正确执行。而Servlet-api.jar也明明包进来了,想请问是不是和TestServlet继承了Servlet有关呢?又该如何修改呢?谢谢:)

banq
2005-09-12 10:37
是classloader问题。

猜你喜欢