You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by Dean Hiller <de...@xsoftware.biz> on 2004/12/18 07:15:44 UTC

classloader problems

I am trying to use JaxME in osgi(same container framework eclipse uses).

My main question is about this line of code(line 91 of Configuration)
        handlerClass = context.getClassLoader().loadClass(pHandlerClass);

Why can't Configuration.class.getClassLoader().loadClass() be used????  Since it is not being used I am running into incompatibilities between osgi and JaxME.  Exception and explanation below.  I am still searching for other possible solutions, but any pointers would be welcome.

Background on osgi.....Basically each jar can make certain packages public and other private.  I have a package that exports 
1. java.xml.bind
2. org.apache.ws.jaxme.impl(ideally I shouldn't have to export this as it is an implementation, but unfortunately, the ObjectFactory in another module is trying to access the impl directly and does not go through the java.xml.bind api)

Another module using that ObjectFactory imports those packages to get past NoClassDefFoundErrors of not finding java.xml.bind.* classes and to find JAXBContextImpl itself....In theory that should have been enough, but I am now running into another class not being found.

Typically in osgi, an external bundle can access just the api classes(ones you import)....those api classes can access impl classes, but your bundle cannot directly access the impl classes.  Here, JAXBContextImpl is an api class which normally works fine and can access impl classes, but because of classloader things that are being done in JAXME, I think this is messing things up when used with osgi.


I am getting the following exception....(Jump to the last part to find the real cause....the class it can't find)
stderr] javax.xml.bind.JAXBException: Failed to parse config file bundle://21/biz/xsoftware/vmaster/binding/Configuration.xml at line 1, column 563: null
[stderr]  at org.apache.ws.jaxme.impl.JAXBContextImpl.init(JAXBContextImpl.java:458)
[stderr]  at org.apache.ws.jaxme.impl.JAXBContextImpl.createContext(JAXBContextImpl.java:521)
[stderr]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[stderr]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[stderr]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[stderr]  at java.lang.reflect.Method.invoke(Method.java:585)
[stderr]  at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:189)
[stderr]  at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:114)
[stderr]  at biz.xsoftware.vmaster.binding.ObjectFactory.<init>(ObjectFactory.java:10)
[stderr]  at biz.xsoftware.impl.vmaster.VMasterServiceImpl.<init>(VMasterServiceImpl.java:34)
[stderr]  at biz.xsoftware.osgi.Activator.start(Activator.java:19)
[stderr]  at org.knopflerfish.framework.BundleImpl$1.run(BundleImpl.java:262)
[stderr]  at java.security.AccessController.doPrivileged(Native Method)
[stderr]  at org.knopflerfish.framework.BundleImpl.start(BundleImpl.java:236)
[stderr]  at org.knopflerfish.bundle.desktop.swing.Desktop.startBundle(Desktop.java:1796)
[stderr]  at org.knopflerfish.bundle.desktop.swing.Desktop.addFile(Desktop.java:2011)
[stderr]  at org.knopflerfish.bundle.desktop.swing.Desktop.drop(Desktop.java:1960)
[stderr]  at java.awt.dnd.DropTarget.drop(DropTarget.java:430)
[stderr]  at sun.awt.dnd.SunDropTargetContextPeer.processDropMessage(SunDropTargetContextPeer.java:500)
[stderr]  at sun.awt.dnd.SunDropTargetContextPeer.access$800(SunDropTargetContextPeer.java:53)
[stderr]  at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchDropEvent(SunDropTargetContextPeer.java:812)
[stderr]  at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchEvent(SunDropTargetContextPeer.java:736)
[stderr]  at sun.awt.dnd.SunDropTargetEvent.dispatch(SunDropTargetEvent.java:29)
[stderr]  at java.awt.Component.dispatchEventImpl(Component.java:3826)
[stderr]  at java.awt.Container.dispatchEventImpl(Container.java:2024)
[stderr]  at java.awt.Component.dispatchEvent(Component.java:3803)
[stderr]  at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
[stderr]  at java.awt.LightweightDispatcher.processDropTargetEvent(Container.java:3963)
[stderr]  at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3817)
[stderr]  at java.awt.Container.dispatchEventImpl(Container.java:2010)
[stderr]  at java.awt.Window.dispatchEventImpl(Window.java:1766)
[stderr]  at java.awt.Component.dispatchEvent(Component.java:3803)
[stderr]  at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
[stderr]  at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
[stderr]  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
[stderr]  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
[stderr]  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
[stderr]  at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

[stderr] Caused by:
[stderr] java.lang.reflect.InvocationTargetException
[stderr]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[stderr]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[stderr]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[stderr]  at java.lang.reflect.Method.invoke(Method.java:585)
[stderr]  at org.apache.ws.jaxme.util.Configurator.startElement(Configurator.java:418)
[stderr]  at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:533)
[stderr]  at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:220)
[stderr]  at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:316)
[stderr]  at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1693)
[stderr]  at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
[stderr]  at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
[stderr]  at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
[stderr]  at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
[stderr]  at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
[stderr]  at org.apache.ws.jaxme.impl.JAXBContextImpl.init(JAXBContextImpl.java:446)
[stderr]  at org.apache.ws.jaxme.impl.JAXBContextImpl.createContext(JAXBContextImpl.java:521)
[stderr]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[stderr]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[stderr]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[stderr]  at java.lang.reflect.Method.invoke(Method.java:585)
[stderr]  at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:189)
[stderr]  at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:114)
[stderr]  at biz.xsoftware.vmaster.binding.ObjectFactory.<init>(ObjectFactory.java:10)
[stderr]  at biz.xsoftware.impl.vmaster.VMasterServiceImpl.<init>(VMasterServiceImpl.java:34)
[stderr]  at biz.xsoftware.osgi.Activator.start(Activator.java:19)
[stderr]  at org.knopflerfish.framework.BundleImpl$1.run(BundleImpl.java:262)
[stderr]  at java.security.AccessController.doPrivileged(Native Method)
[stderr]  at org.knopflerfish.framework.BundleImpl.start(BundleImpl.java:236)
[stderr]  at org.knopflerfish.bundle.desktop.swing.Desktop.startBundle(Desktop.java:1796)
[stderr]  at org.knopflerfish.bundle.desktop.swing.Desktop.addFile(Desktop.java:2011)
[stderr]  at org.knopflerfish.bundle.desktop.swing.Desktop.drop(Desktop.java:1960)
[stderr]  at java.awt.dnd.DropTarget.drop(DropTarget.java:430)
[stderr]  at sun.awt.dnd.SunDropTargetContextPeer.processDropMessage(SunDropTargetContextPeer.java:500)
[stderr]  at sun.awt.dnd.SunDropTargetContextPeer.access$800(SunDropTargetContextPeer.java:53)
[stderr]  at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchDropEvent(SunDropTargetContextPeer.java:812)
[stderr]  at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchEvent(SunDropTargetContextPeer.java:736)
[stderr]  at sun.awt.dnd.SunDropTargetEvent.dispatch(SunDropTargetEvent.java:29)
[stderr]  at java.awt.Component.dispatchEventImpl(Component.java:3826)
[stderr]  at java.awt.Container.dispatchEventImpl(Container.java:2024)
[stderr]  at java.awt.Component.dispatchEvent(Component.java:3803)
[stderr]  at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
[stderr]  at java.awt.LightweightDispatcher.processDropTargetEvent(Container.java:3963)
[stderr]  at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3817)
[stderr]  at java.awt.Container.dispatchEventImpl(Container.java:2010)
[stderr]  at java.awt.Window.dispatchEventImpl(Window.java:1766)
[stderr]  at java.awt.Component.dispatchEvent(Component.java:3803)
[stderr]  at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
[stderr]  at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
[stderr]  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
[stderr]  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
[stderr]  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
[stderr]  at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

[stderr] Caused by: java.lang.NoClassDefFoundError: org/apache/ws/jaxme/JMHandler
[stderr]  at java.lang.ClassLoader.defineClass1(Native Method)
[stderr]  at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
[stderr]  at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
[stderr]  at org.knopflerfish.framework.BundleClassLoader.loadOwnClass(BundleClassLoader.java:298)
[stderr]  at org.knopflerfish.framework.BundleClassLoader.findClass(BundleClassLoader.java:136)
[stderr]  at org.knopflerfish.framework.BundleClassLoader.loadClass(BundleClassLoader.java:224)
[stderr]  at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
[stderr]  at org.apache.ws.jaxme.impl.Configuration$Manager.setHandlerClass(Configuration.java:91)
[stderr]  ... 52 more

Re: classloader problems

Posted by Dean Hiller <de...@xsoftware.biz>.
> to obtain a context. For obvious reasons, the supplied ClassLoader is
> the one, that ought to be used for loading schema related classes.

Actually, this is a feature I was going to add in JAXME which allows
multiple services in J2EE containers to use one JAXME, instead of having to
have one per service which JAXB currently forces on us by the one
classLoader that would be specified.

The error I was getting however was loading a JAXME implementation class,
not a JAXB generated object.  Looking at JAXBContext, I know the same
context classLoader is used to load a JAXB implementation which I think can
be really dangerous if J2EE wants to provide a JAXB implementation as a
service.  Then if it is loaded by the system classloader, the J2EE services
in the container can't have their JAXB objects registered.

One last question, if JAXBContext loads your JAXBContextImpl from the
context class loader and JAXBContextImpl is loading Configuration in terms
of it's own classloader, shouldn't Configuration just be able to load the
JMHandler using Configuration.class.getClassLoader as that classloader would
be the same as the one that loaded JAXBContextImpl and would also get rid of
my problem at the same time(and future problems as J2EE plays similar
classloader games).

In fact, I am pretty sure if you stuff works in osgi, it would work in J2EE
by default...not 100% sure though.
thanks,
dean

----- Original Message ----- 
From: "Jochen Wiedmann" <jo...@gmail.com>
To: "Dean Hiller" <de...@xsoftware.biz>
Cc: <ja...@ws.apache.org>
Sent: Monday, December 20, 2004 12:58 AM
Subject: Re: classloader problems


> Hi, Dean,
>
> On Fri, 17 Dec 2004 23:15:44 -0700, Dean Hiller <de...@xsoftware.biz>
wrote:
>
> > My main question is about this line of code(line 91 of Configuration)
> >         handlerClass =
context.getClassLoader().loadClass(pHandlerClass);
> >
> > Why can't Configuration.class.getClassLoader().loadClass() be used????
>
> Because that would possibly be the right ClassLoader to use in your
> particular situation. However, there are a lot of other cases, where
> it would be not. For example, consider the following:
>
> It is discusses, to make JAXB a part of J2EE, or even J2SE. Within an
> EJB container, the ClassLoader would consequently be the containers
> classloader or even the system classloader. Your jar files are
> typically invisible for that ClassLoader.
>
> The suggested idea is, that *you* pick a suitable ClassLoader and then use
>
>     JAXBContextImpl(String, ClassLoader9
>
> to obtain a context. For obvious reasons, the supplied ClassLoader is
> the one, that ought to be used for loading schema related classes.
>
>
> Jochen


---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org


Re: classloader problems

Posted by Dean Hiller <de...@xsoftware.biz>.
also, please realize that the class not found was from what looked like an
Implementation class of JaxME, not a JAXB generated object.  The
ClassNotFound was on JMHandler.....notice JAXBContextImpl is loading just
fine from the context loader, and if JMHandler.

I will research more and ask some more questions....sorry this is a
complicated issue I am playing with and trying to understand.
thanks,
dean


----- Original Message ----- 
From: "Jochen Wiedmann" <jo...@gmail.com>
To: "Dean Hiller" <de...@xsoftware.biz>
Cc: <ja...@ws.apache.org>
Sent: Monday, December 20, 2004 12:58 AM
Subject: Re: classloader problems


> Hi, Dean,
>
> On Fri, 17 Dec 2004 23:15:44 -0700, Dean Hiller <de...@xsoftware.biz>
wrote:
>
> > My main question is about this line of code(line 91 of Configuration)
> >         handlerClass =
context.getClassLoader().loadClass(pHandlerClass);
> >
> > Why can't Configuration.class.getClassLoader().loadClass() be used????
>
> Because that would possibly be the right ClassLoader to use in your
> particular situation. However, there are a lot of other cases, where
> it would be not. For example, consider the following:
>
> It is discusses, to make JAXB a part of J2EE, or even J2SE. Within an
> EJB container, the ClassLoader would consequently be the containers
> classloader or even the system classloader. Your jar files are
> typically invisible for that ClassLoader.
>
> The suggested idea is, that *you* pick a suitable ClassLoader and then use
>
>     JAXBContextImpl(String, ClassLoader9
>
> to obtain a context. For obvious reasons, the supplied ClassLoader is
> the one, that ought to be used for loading schema related classes.
>
>
> Jochen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: jaxme-dev-help@ws.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org


Re: classloader problems

Posted by Jochen Wiedmann <jo...@gmail.com>.
Hi, Dean,

On Fri, 17 Dec 2004 23:15:44 -0700, Dean Hiller <de...@xsoftware.biz> wrote:

> My main question is about this line of code(line 91 of Configuration) 
>         handlerClass = context.getClassLoader().loadClass(pHandlerClass); 
>   
> Why can't Configuration.class.getClassLoader().loadClass() be used???? 

Because that would possibly be the right ClassLoader to use in your
particular situation. However, there are a lot of other cases, where
it would be not. For example, consider the following:

It is discusses, to make JAXB a part of J2EE, or even J2SE. Within an
EJB container, the ClassLoader would consequently be the containers
classloader or even the system classloader. Your jar files are
typically invisible for that ClassLoader.

The suggested idea is, that *you* pick a suitable ClassLoader and then use

    JAXBContextImpl(String, ClassLoader9

to obtain a context. For obvious reasons, the supplied ClassLoader is
the one, that ought to be used for loading schema related classes.


Jochen

---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org