Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sorted this now, thanks to Ales Justin on the JBoss.org forum (<a href="http://community.jboss.org/message/616328" rel="nofollow">http://community.jboss.org/message/616328</a>).</p> <p>Basically, my registration code was calling the only public method available to register the mbean, <code>MBeanServer.registerMBean(Object object, ObjectName name)</code>. This doesn't specify a classloader, and the classloader registered with the bean in the JMX registry is therefore null. </p> <p>This means that when you invoke a method on the bean via the JMX console in the browser, it falls back to the classloader on the invoking thread - not helpful if you're trying to do anything involved, as it won't have any of your classes, hence the error above.</p> <p>Ales pointed me at an alternative way of registering the bean which overcomes this issue, which is used in JBoss service code. So <strong>instead</strong> of </p> <pre><code>DynamicMBean mBean = getMBeanFactory().createMBean(this); MBeanServer mBeanServer = MBeanServerLocator.instance().getmBeanServer(); ObjectName name; try { name = new ObjectName(jmxObjectName); mBeanServer.registerMBean(mBean, name); } catch (Throwable t) { log.error(String.format("Unable to register [%s] with JMX under [%s]:", serviceName, jmxObjectName), t); } </code></pre> <p>I'm now using</p> <pre><code>DynamicMBean mBean = getMBeanFactory().createMBean(this); MBeanServer mBeanServer = MBeanServerLocator.instance().getmBeanServer(); ObjectName name; try { name = new ObjectName(jmxObjectName); Map&lt;String, Object&gt; values = new HashMap&lt;String, Object&gt;(); ClassLoader classLoader = this.getClass().getClassLoader(); log.info(String.format("Registering to JMX with classLoader [%s]",classLoader.toString())); values.put(ServerConstants.CLASSLOADER, classLoader); mBeanServer.invoke( ObjectNameFactory.create(ServerConstants.MBEAN_REGISTRY), "registerMBean", new Object[] { mBean, name, values }, new String[] { Object.class.getName(), ObjectName.class.getName(), Map.class.getName() } ); } catch (Throwable t) { log.error(String.format("Unable to register [%s] with JMX under [%s]:", serviceName, jmxObjectName), t); } </code></pre> <p>This is taken from <code>org.jboss.system.ServiceCreator.installPlainMBean(MBeanServer server, ObjectName objectName, ServiceMetaData metaData)</code>. You invoke registerMBean on the MbeanResgistry bean itself, it seems, and here you can pass a classloader, which is then switched to when you invoke the bean method in the browser.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload