-
1. Re: ClassLoader can not find a MBean class that sits in the
dimitris Nov 16, 2004 4:20 PM (in response to vitaly1)You need to use the classloader that loaded the 1st MBean, e.g:
Object mybean = Class.forName("com.percussion.jmx.test.SimpleListener", true, this.getClass().getClassLoader()).newInstance(); server.registerMBean(mybean, "mydomain:name=myname");
There is also the createMBean() that takes the ObjectName of a classloader, but I'm not sure how to map the context thread classloader to the ObjectName under which it is registered. -
2. Re: ClassLoader can not find a MBean class that sits in the
vitaly1 Nov 16, 2004 4:32 PM (in response to vitaly1)Wonder if this will work too?
trying it now..
ClassLoader cl = this.getClass().getClassLoader();
obj = server.createMBean(className,
getObjectName(),
cl,
getMethodArguments(this, server),
getJMXMethodSignature(this)); -
3. Re: ClassLoader can not find a MBean class that sits in the
vitaly1 Nov 16, 2004 4:40 PM (in response to vitaly1)oops, it actually expects ObjectName loaderName
how do I get ObjectName of the loader? -
4. Re: ClassLoader can not find a MBean class that sits in the
vitaly1 Nov 16, 2004 5:00 PM (in response to vitaly1)If I can not use this method, that means I need
to do all the introspection, call a constructor myself
isn't there a better way to do it?
ObjectInstance createMBean(java.lang.String className, ObjectName name, ObjectName loaderName, java.lang.Object[] params, java.lang.String[] signature) -
5. Re: ClassLoader can not find a MBean class that sits in the
vitaly1 Nov 16, 2004 5:29 PM (in response to vitaly1)So, I ended up with this code:
The trouble is it not working just like before - ClassNotFoundException :(
eflectionException: Class not found: com.percussion.jmx.test.SimpleListener Cause: java.lang.ClassNotFoundException: com.percussion.jmx.test.SimpleListener
ClassLoader cl = this.getClass().getClassLoader();
Class clazz = Class.forName(className,
true,
this.getClass().getClassLoader());
Constructor handlerCtor = clazz.getConstructor(
getMethodSignature(this));
java.lang.Object beanInst =
handlerCtor.newInstance( getMethodArguments(this, server) );
obj = server.registerMBean(beanInst, getObjectName()); -
6. Re: ClassLoader can not find a MBean class that sits in the
dimitris Nov 16, 2004 5:48 PM (in response to vitaly1)out of curiocity, what are those:
getMethodSignature(this)
getMethodArguments(this, server)
getObjectName()
Isn't you 1st mbean loaded using a -service.xml or .sar archive?
What is the use case you are trying to implement? -
7. Re: ClassLoader can not find a MBean class that sits in the
vitaly1 Nov 17, 2004 12:12 AM (in response to vitaly1)Hi !
those are my methods :) (derived from MX4J) one gets signature Class[]
another actual values and getObject gives ObjectName instance
The use case is like this:
1. I want to be able to load the same JMX beans on JBoss, Bea, etc.
2. To do the above I defined my own xml config file (enhaced MX4J one)
3. For each app server I will build one app server specific loader; in JBoss
case that is a service MBean
4. So I have a sar with one JBoss specific MBean that creates another MBean (non JBoss specific) that guy loads up my xml config file and creates all the rest of the beans, creates listeners, relationships, etc.
All these classes sit inside the same SAR file, which really puzzles me why JBoss can not find simple Bean classes that are practically sit next to the service class only in a different package? -
8. Re: ClassLoader can not find a MBean class that sits in the
dimitris Nov 17, 2004 5:27 AM (in response to vitaly1)The example code I showed you, works for at least one component I know. From which line exactly the exception comes from? (fromName(), newInstance()?)
Try calling the default CTOR.
Also from the 3 methods getXXX() it seems as if you try to replicate the same running MBean, e.g. getObjectName() what does it return?
Show the mbean descriptor, too. -
9. Re: ClassLoader can not find a MBean class that sits in the
vitaly1 Nov 17, 2004 11:34 AM (in response to vitaly1)Dimitris,
I sent you my sources, see if something jumps out -
10. Re: ClassLoader can not find a MBean class that sits in the
vitaly1 Nov 17, 2004 12:02 PM (in response to vitaly1)1. JBoss loads us PSJmxJBossService
that one creates another MBean
PSJmxConfigurationLoader
2. PSJmxConfigurationLoader fetches my xml
file with all the beans definitions in it and
uses PSJmxDefaultConfigurationBuilder
to load all those beans up
3. The PSJmxDefaultConfigurationBuilder
has one inner class for each xml node in
the xml config file under com.percussion.jmx.config
ie: node is first parsed then there
is a second run when PSJmxDefaultConfigurationBuilder
instantiates all those MBeans and registers
them with MBeanServer -
11. Re: ClassLoader can not find a MBean class that sits in the
dimitris Nov 18, 2004 5:22 AM (in response to vitaly1)Could you be a little more careful (or just buy some JBoss support)? Your configuration file tries to load mx4j classes. If you comment that out, it works.
Caused by: java.lang.ClassNotFoundException: No ClassLoaders found for: mx4j.too ls.adaptor.http.HttpAdaptor at org.jboss.mx.loading.LoadMgr3.beginLoadTask(Unknown Source) at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(Unknown Sour ce) at org.jboss.mx.loading.RepositoryClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(ClassLoader.java:235) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:219) at com.percussion.jmx.config.PSJmxDefaultConfigurationBuilder$Create.con figure(PSJmxDefaultConfigurationBuilder.java:333) ... 72 more
<!-- <create className="mx4j.tools.adaptor.http.HttpAdaptor" objectName="connectors:type=http" loaderName="null"> <arg type="int" name="port">9090</arg> <arg type="string" name="host">localhost</arg> </create> <create className="mx4j.tools.adaptor.http.XSLTProcessor" objectName="connectors:type=http,processor=xslt" loaderName="null"/> <call objectName="connectors:type=http" attribute="ProcessorNameString"> <arg type="string" name="connName">connectors:type=http,processor=xslt</arg> </call> <call objectName="connectors:type=http" operation="start"/> -->
-
12. Re: ClassLoader can not find a MBean class that sits in the
vitaly1 Nov 18, 2004 12:25 PM (in response to vitaly1)Thanks a lot!
The above MX4J stuff got in by accident, but the bigger issue was that I left a older sar under /lib
so, I kept trying and trying not realizing that JBoss
was actually running my older code!
I appreciate your help
Thanks,
-Vitaly