Why don't you just call unregisterMBean() on the MBeanServer ?
Something like (Pseudocode)
MbeanServer mbs = MbeanServerLocator.locateJBoss(); ObjectName on = new ObjectName("foo:type=service"); mbs.unregisterMBean(on);
this could also be done on command line via twiddle:
twiddle unregister "foo:type=service"
Thanks! However I found another solution. It isn't really related to JBoss since I'm using Spring to manage these beans, but here goes:
I added the following line to the "MBeanExporter" in applicationContext.xml which forces unregistration of any existing beans with the same name. (this setting probably does the same as the code you posted does)
<property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING"/>