开发遇到问题

The MBean class could not be loaded by the default loader repository

 

jmx-1_2_1-bin

jmxremote-1_0_1

 

 

注册MBean时报错
javax.management.ReflectionException: The MBean class could not be loaded by the default loader repository
 at com.sun.jmx.mbeanserver.MBeanInstantiatorImpl.findClassWithDefaultLoaderRepository(MBeanInstantiatorImpl.java:61)
 at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(DefaultMBeanServerInterceptor.java:271)
 at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(DefaultMBeanServerInterceptor.java:211)
 at com.sun.jmx.mbeanserver.JmxMBeanServer.createMBean(JmxMBeanServer.java:408)
 at com.huawei.rms.jmx.server.ClientMBeanServer.registerMBean(ClientMBeanServer.java:186)
 at com.huawei.rms.jmx.server.ClientMBeanServer.init(ClientMBeanServer.java:80)
 at com.huawei.rms.jmx.server.interceptor.RMSClientInterceptor.start(RMSClientInterceptor.java:67)
 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:585)
 at

 

 

 

 

First of all, if registerMBean is enough for you then you should stick with it. createMBean introduces exactly the sort of problems you are seeing. It is only really useful if you need to call it remotely, when registerMBean is unavailable.

If you do need to support createMBean, then you'll want to have a look at Chapter 8, "Advanced Dynamic Loading", in the JMX specification at <http://download.java.net/jdk6/docs/technotes/guides/jmx/JMX_1_4_specification.pdf>. (This is the specification for Java SE 6, but this particular aspect hasn't changed since the previous version which is in J2SE 5.0.)

Basically you need to have your URLClassLoader be an MBean and register it in the MBeanServer. The quickest way to achieve this is to use the existing MLet class, which is a subclass of URLClassLoader. However, MLet brings along a whole bunch of functionality which you probably don't need, so I think a better approach would be to define your own ClassLoader MBean like this:

public interface MyClassLoaderMBean {}   public class MyClassLoader extends URLClassLoader implements MyClassLoaderMBean { public MyClassLoader(URL[] urls, ClassLoader parent) { super(urls, parent); } } 



Then you can either use MyClassLoader where you currently use URLClassLoader, or you can specify your existing URLClassLoader as the parent of the MyClassLoader and give MyClassLoader an empty set of URLs.

 

 

 

 

http://verran.iteye.com/blog/127882

你可能感兴趣的:(java,.net,J2SE,Blog,sun)