I have a webapp deployed in Tomcat 7.0.8. Recently I started implementing MBeans to be able to monitor a few actions, which normally are invoked from a quartz scheduler. I connect to Tomcat's MBean server using JConsole and invoke a method, which tries to connect to a database via JNDI.
When execution reaches
Context initContext = new InitialContext();
the following exception is thrown:
javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory]
When the method is called from the regular servlet (a JAX-WS webservice), there are no problems with the class loading. It seems class loading works differently when JMX is involved, but I can't figure out how... Could it have something to do with RMI class loader disabled
, which JConsole tells me?
Yes. It's actually a little more complex then that; you're used to the Web Container - but JMX MBeans run in a different container (with a seperate life-cycle). That is the MBeanServer.