Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » (no subject)
(no subject) [message #693255] Wed, 06 July 2011 06:13 Go to next message
Michael Gerzabek is currently offline Michael GerzabekFriend
Messages: 16
Registered: June 2011
Junior Member
Hi,

I try to setup the wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted as an OSGI bundle.

MANIFEST.MF:
Require-Bundle: javax.xml.bind;bundle-version="2.2.0",
org.eclipse.persistence.moxy;bundle-version="2.1.3"

Launch configuration:
org.eclipse.persistence.core startlevel 2 auto-start true
my bundle startlevel 3 auto-start true

When running equinox I get the exception:

javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: org.eclipse.persistence.jaxb.JAXBContextFactory]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:186)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:330)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:618)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:565)

What do I miss here? How do I have to setup my bundle project when using MOXy in an OSGI bundle?

Regards,
Michael
Boostrapping MOXy JAXB in OSGi [message #693513 is a reply to message #693255] Wed, 06 July 2011 16:10 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun SmithFriend
Messages: 197
Registered: July 2009
Senior Member
You'll need to pass a classloader that has visibility of the domain classes and MOXy when you create your context. JAXB wasn't designed for OSGi and so when bootstrapping an implementation like MOXy the SPI classes need a classloader that can see the desired implementation.

--Shaun
Re: Boostrapping MOXy JAXB in OSGi [message #693554 is a reply to message #693513] Wed, 06 July 2011 18:31 Go to previous messageGo to next message
Michael Gerzabek is currently offline Michael GerzabekFriend
Messages: 16
Registered: June 2011
Junior Member
Okay, and thank you for your reply!

I'm relatively new to equinox/OSGI and RCP. So please excuse the blond question: How do I do this?

When I do something like
JAXBContext jaxbContext = JAXBContext.newInstance(
	"org.jessas.annotator.jaxb.moxy",
	Customer.class.getClassLoader());

I get
Exception [EclipseLink-50000] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.JAXBException
Exception Description: The path org.jessas.annotator.jaxb.moxy contains no ObjectFactory or jaxb.index file and no sessions.xml was found
	at org.eclipse.persistence.exceptions.JAXBException.noObjectFactoryOrJaxbIndexInPath(JAXBException.java:91)
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:178)


Customer is one Bean that sits in the package which is supplied via newInstance (s.a.). This is the classloader of the bundle that should also see the MOXy libraries.

Any help warmly appreciated,
regards,
Michael
(no subject) [message #693558 is a reply to message #693255] Wed, 06 July 2011 18:32 Go to previous messageGo to next message
Michael Gerzabek is currently offline Michael GerzabekFriend
Messages: 16
Registered: June 2011
Junior Member
Somehow this thread got posted twice. Conversation continued here: http://www.eclipse.org/forums/index.php/m/693554/#msg_693554
Re: Boostrapping MOXy JAXB in OSGi [message #693559 is a reply to message #693554] Wed, 06 July 2011 18:40 Go to previous messageGo to next message
Michael Gerzabek is currently offline Michael GerzabekFriend
Messages: 16
Registered: June 2011
Junior Member
And here ist the answer (from http://stackoverflow.com/questions/2667724/do-you-always-need-an-objectfactory-class-when-using-jaxb):

I added a jaxb.index file in the package where the beans are located. This file contains a list of their simple names. for the wiki sample the file looks like

Address
Customer
PhoneNumber


Now everything works fine.
Thank you!
Michael
Re: Boostrapping MOXy JAXB in OSGi [message #693586 is a reply to message #693559] Wed, 06 July 2011 19:51 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun SmithFriend
Messages: 197
Registered: July 2009
Senior Member
Glad you found an answer! FYI, you could also pass an array of classes when you create your context rather than the package name.

--Shaun
(no subject) [message #693595 is a reply to message #693559] Wed, 06 July 2011 19:51 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun SmithFriend
Messages: 197
Registered: July 2009
Senior Member
Glad you found an answer! FYI, you could also pass an array of classes when you create your context rather than the package name.

--Shaun
Re: (no subject) [message #693739 is a reply to message #693595] Thu, 07 July 2011 06:24 Go to previous messageGo to next message
Michael Gerzabek is currently offline Michael GerzabekFriend
Messages: 16
Registered: June 2011
Junior Member
I see. But how do I set the classloader in that case?

Thank you,
Michael
(no subject) [message #693756 is a reply to message #693586] Thu, 07 July 2011 06:24 Go to previous messageGo to next message
Michael Gerzabek is currently offline Michael GerzabekFriend
Messages: 16
Registered: June 2011
Junior Member
I see. But how do I set the classloader in that case?

Thank you,
Michael
Re: (no subject) [message #693927 is a reply to message #693739] Thu, 07 July 2011 13:48 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun SmithFriend
Messages: 197
Registered: July 2009
Senior Member
When you pass an array of classes the classloader used by the JAXB bootstrap classes is obtained from the classes themselves. So this means that the domain classes' bundle would need to have visibility to MOXy. Again, JAXB wasn't designed for OSGi so the API isn't ideal.

--Shaun
Re: (no subject) [message #693936 is a reply to message #693927] Thu, 07 July 2011 14:04 Go to previous message
Michael Gerzabek is currently offline Michael GerzabekFriend
Messages: 16
Registered: June 2011
Junior Member
This is interesting!

I tried three different calls, only the first of them works:

JAXBContext jaxbContext = JAXBContext.newInstance(
	"org.jessas.annotator.jaxb.moxy",
	Customer.class.getClassLoader());


These two
JAXBContext jaxbContext = JAXBContext.newInstance(
        Customer.class, Address.class, PhoneNumber.class);


JAXBContext jaxbContext = JAXBContext.newInstance(new Class[] {
	Customer.class, Address.class, PhoneNumber.class },
	Collections.<String, Object> emptyMap());


both result in
javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.ClassNotFoundException: org.eclipse.persistence.jaxb.JAXBContextFactory]
	at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:186)
	at javax.xml.bind.ContextFinder.find(ContextFinder.java:330)
	at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:618)
	at org.jessas.annotator.jaxb.Activator.doit(Activator.java:77)
	at org.jessas.annotator.jaxb.Activator.start(Activator.java:33)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:783)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:774)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:755)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:370)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:374)
	at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1067)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:561)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:546)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:459)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:440)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:227)
	at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:337)
Caused by: java.lang.ClassNotFoundException: org.eclipse.persistence.jaxb.JAXBContextFactory
	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
	at org.eclipse.core.runtime.internal.adaptor.ContextFinder.loadClass(ContextFinder.java:129)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
	at javax.xml.bind.ContextFinder.safeLoadClass(ContextFinder.java:480)
	at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:184)
	... 18 more


Anyway. I see how easy it is to use moxy and am happy to provide the ClassLoader by hand. This way I can use it in my bundle an proceed with my requirements.
Thank you for your kind support.

Regards,
Michael
(no subject) [message #693939 is a reply to message #693739] Thu, 07 July 2011 13:48 Go to previous message
Shaun Smith is currently offline Shaun SmithFriend
Messages: 197
Registered: July 2009
Senior Member
When you pass an array of classes the classloader used by the JAXB bootstrap classes is obtained from the classes themselves. So this means that the domain classes' bundle would need to have visibility to MOXy. Again, JAXB wasn't designed for OSGi so the API isn't ideal.

--Shaun
Previous Topic:Circular references with identity id - what's the right way?
Next Topic:(no subject)
Goto Forum:
  


Current Time: Thu Apr 18 18:25:31 GMT 2024

Powered by FUDForum. Page generated in 0.01817 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top