Chapter 6. FAQ

Table of Contents

MX4J Frequently Asked Questions

MX4J Frequently Asked Questions

Simone Bordet

Revision History
Revision $Revision: 1.4 $$Date: 2002/10/03 08:37:20 $

1. Why does MBeanServer.createMBean("my.class.Name", new ObjectName("domain:key=value")) throws ClassNotFoundException ?

This is a lack in the JMX specification that will be fixed in JMX 1.2.
The JMX RI inserts by default the system classloader (the one that loads the classes from the classpath) into the DefaultLoaderRepository. The MBeanServer's call above uses the DefaultLoaderRepository to find the specified class.
However, the JMX specification does not say that the DefaultLoaderRepository must have the system classloader in its list of classloaders, but only MBeans that are instance of java.lang.ClassLoader (and of course the system classloader is not an MBean).
So, relying on this undocumented feature of the JMX RI will make your applications non-portable across JMX implementations.
The suggested way to workaround the problem is using this overloaded version of the invocation above:
MBeanServer.createMBean("my.class.Name", new ObjectName("domain:key=value"), null).
With this version, the class is loaded by the same classloader that loaded the MBeanServer class - normally the system classloader - and works well also in the JMX RI (and in any other compliant JMX implementation).

2. How can I change the default log level of the MX4J implementation to understand what is going on ?

Just set the system property 'mx4j.log.priority' to one of these values (from less verbose to more verbose):

  • fatal
  • error
  • warn
  • info
  • debug
  • trace
like this example command line:

>java -Dmx4j.log.priority=debug -classpath . my.package.Application

See the MX4J documentation about logging for more information.