Hello!

Felix Meschberger wrote:
Hi Miguel,

>From the stack trace, I assume you want to create an MBean using the JMX
Server. For this to work, the JMX Server of course has to have some
knowledge of the class loaders used. In plain old Java applications this
is not so big of an issue.

In OSGi frameworks, this is more involved: You would have to provide the
JMX Server some support in loading the classes, which is defined in the
JMX spec (and which escapes my mind currently of what is to be done, but
IIRC you would have to do some stuff with ClassLoaderRepository...)

I assume, your JMX Server is running in the Java VM environment and your
MBean is located in the Bundle. 

Yes that is my case.
So you would have to make sure the JMX
Server knows about how to load the MBeans from within the Bundles -
given that Bundles may come and go, this sounds like tricky. Generally I
try no to use the JMX Server to create MBeans because of these issues.
  
 How do you create the MBeans ?
Finally, you say "external library" and refer to the Bundle-Classpath
manifest header. This sounds like a misconception: The Bundle-Classpath
lists additional locations, jar files generally, inside the bundle,
which should be used to build to the class loader for the bundle.
External Libraries are referred to by Import-Package headers and must be
provided by other bundles (through their Export-Package headers) or by
the org.osgi.framework.system.packages or
org.osgi.framework.bootdelegation system properties.
  

  Yes that is right. With external "library" I tried to say an external package to my code ;)
  I am using the Bundle-Classpath to load the jar that is present inside the bundle. That is working fine but thanks for the correction ;)

 As a side question is this a general problem when using reflection in a osgi environment?

Miguel Matos
Hope this helps.

Regards
Felix

Am Dienstag, den 11.09.2007, 23:28 +0100 schrieb MMatos:
  
Hello!

 I've been playing with apache felix for some months. Now I am building 
a bundle that depends on external jars and use a bit of reflection.

 To overcome the problem of the external library I have used the 
Bundle-ClassPath: manifest header.
 
 Currently my problem is when I tried to load a class using reflection 
and I get a class not found exception.
 

javax.management.ReflectionException: The MBean class could not be 
loaded by the default loader repository
        at 
com.sun.jmx.mbeanserver.MBeanInstantiatorImpl.findClassWithDefaultLoaderRepository(MBeanInstantiatorImpl.java:61)
        at 
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(DefaultMBeanServerInterceptor.java:271)
        at 
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.createMBean(DefaultMBeanServerInterceptor.java:211)
        at 
com.sun.jmx.mbeanserver.JmxMBeanServer.createMBean(JmxMBeanServer.java:408)
        at kAdapt.mbeanServer.MainServer.registerMBean(MainServer.java:131)


Caused by: java.lang.ClassNotFoundException: kAdapt.mbeanServer.InfoMBean
        at 
com.sun.jmx.mbeanserver.ClassLoaderRepositorySupport.loadClass(ClassLoaderRepositorySupport.java:208)
        at 
com.sun.jmx.mbeanserver.ClassLoaderRepositorySupport.loadClass(ClassLoaderRepositorySupport.java:128)
        at 
com.sun.jmx.mbeanserver.MBeanInstantiatorImpl.findClassWithDefaultLoaderRepository(MBeanInstantiatorImpl.java:58)
        ... 18 more


 The class in question kAdapt.mbeanServer.InfoMBean is of course in the 
package hierarchy but the osgi classloader seems to miss it ...
  I would like to know why this happens and the solution.

( In this particular problem the class failing to load is an MBean when 
trying to create it
-->>        at 
com.sun.jmx.mbeanserver.MBeanInstantiatorImpl.findClassWithDefaultLoaderRepository(MBeanInstantiatorImpl.java:61)
but I think that this problem will happen whenever one uses reflection 
... Am I right ?
)

I tried with DynamicImport-Package but without success too ...

Here is my manifest

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Build-Jdk: 1.5.0_12
Bundle-Activator: kAdapt.Activator
DynamicImport-Package: kAdapt.mbeanServer    <<---- the class not found 
is here
Bundle-ClassPath: .,kAdapt,js-1.6R5.jar
Import-Package: org.osgi.framework;version=1.3,org.osgi.service.log;ve
 rsion=1.3,javax.management.remote,javax.management,javax.xml.parsers,
 org.w3c.dom,org.xml.sax
Bundle-ManifestVersion: 2

Any guidance will be greatly appreciated.

Miguel Matos

PS: I think I could use the jmx facilities provided by felix ( I am 
already doing that in another bundle, but that is not the point in my 
question....))

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

    


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


  
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to