Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JAXB with Eclipse RCP(UnmarshalException - A descriptor with default root element [xml-root] was not found in the project)
JAXB with Eclipse RCP [message #991574] Wed, 19 December 2012 19:13 Go to next message
michael jordan is currently offline michael jordanFriend
Messages: 3
Registered: December 2012
Junior Member
1) setup
i have an eclipse 3.7 plug-in project that runs an eclipse rcp application
the execution environment under run configuration is set to "Runtime JRE: jre6 (32bit)"

editing plugin.xml with the "Plug-In Manifest Editor" org.eclipse.persistence.moxy (2.4.1) is added under required plugins in the "Dependencies" tab

the plugin-in is from the eclipselink download page from the "EclipseLink 2.4.1 OSGi Bundles Zip (18 MB)" download


2) model
i have generated the model using eclipselink-2.4.1.v20121003-ad44345

in addition to the generated model java classes ObjectFactory.java and jaxb.properties were also created (the content of jaxb.properties being "javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory")

the root element in the xml is "<plan-library>"
the corresponding java class is annotated
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "deltaLinkOrGmtLink",
    "bibrefOrCommentOrNotYetDefinedOrUrl",
    "libraryInfo",
    "domainDefs",
    "libraryDefs",
    "plans"
})
@XmlRootElement(name = "plan-library")
public class PlanLibrary {


3) unmarshalling

import org.eclipse.persistence.jaxb.JAXBContext;
import org.eclipse.persistence.jaxb.JAXBUnmarshaller;
import at.ac.tuwien.ieg.asbruedit.model.asbru.ObjectFactory;

...

			JAXBContext jc = (JAXBContext) JAXBContext.newInstance("at.ac.tuwien.ieg.asbruedit.model.asbru", ObjectFactory.class.getClassLoader());
			JAXBUnmarshaller u = jc.createUnmarshaller();
			Object planLibrary = u.unmarshal(input.getAsbruXmlFile()); // <-- exception here


this leads to the following exception:
javax.xml.bind.UnmarshalException
 - with linked exception:
[Exception [EclipseLink-25008] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: A descriptor with default root element plan-library was not found in the project]
	at org.eclipse.persistence.jaxb.JAXBUnmarshaller.handleXMLMarshalException(JAXBUnmarshaller.java:1014)
	at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:126)
	at at.ac.tuwien.ieg.asbruedit.editor.AsbruEditor.initializeGraphicalViewer(AsbruEditor.java:36)
...


4) unmarshalling with the native jaxb implementation - ie. simply removing the jaxb.properties file and changing the code
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import at.ac.tuwien.ieg.asbruedit.model.asbru.ObjectFactory;

...

			JAXBContext jc = JAXBContext.newInstance("at.ac.tuwien.ieg.asbruedit.model.asbru", ObjectFactory.class.getClassLoader());
			Unmarshaller u = jc.createUnmarshaller();
			Object planLibrary = u.unmarshal(input.getAsbruXmlFile());


works perfectly

5) the point: what am i doing wrong?

note 1:
using jaxb.properties (ie. eclipselink) the following piece of code
javax.xml.bind.JAXBContext jc = javax.xml.bind.JAXBContext.newInstance("at.ac.tuwien.ieg.asbruedit.model.asbru", ObjectFactory.class.getClassLoader());


produces a "java.lang.ClassCastException: org.eclipse.persistence.jaxb.JAXBContext cannot be cast to javax.xml.bind.JAXBContext"

which should be impossible since org.eclipse.persistence.jaxb.JAXBContext extends javax.xml.bind.JAXBContext; newInstance even returns against javax.xml.bind.JAXBContext (just simple covariance... so maybe there is some osgi magic at work here that i don't get OR im too tired from this and just missing something super obvious)

note 2:
similar story with

			org.eclipse.persistence.jaxb.JAXBContext jc = (org.eclipse.persistence.jaxb.JAXBContext) org.eclipse.persistence.jaxb.JAXBContext.newInstance("at.ac.tuwien.ieg.asbruedit.model.asbru", ObjectFactory.class.getClassLoader());
			javax.xml.bind.Unmarshaller u = jc.createUnmarshaller();
			Object planLibrary = u.unmarshal(input.getAsbruXmlFile()); //<-- exception happens here 


"java.lang.IncompatibleClassChangeError: Class org.eclipse.persistence.jaxb.JAXBUnmarshaller does not implement the requested interface javax.xml.bind.Unmarshaller"
Re: JAXB with Eclipse RCP [message #992002 is a reply to message #991574] Thu, 20 December 2012 16:34 Go to previous message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
Registered: July 2009
Senior Member

Hi Michael,

Below is a link to an answer I gave on Stack Overflow that has a complete example of using MOXy in an OSGi environment.

- http://stackoverflow.com/a/12943115/383861

To specifically address #5, you need to ensure that you are importing either the JAXB bundle or the javax.xml.bind package. Since MOXy imports this if you don't then MOXy will get the JAXB classes from OSGi and you'll get them from the JRE and you'll get the exception you are seeing.

-Blaise
Previous Topic:Maintain Insert order while inserting in a table
Next Topic:Named queries with dynamic entities?
Goto Forum:
  


Current Time: Tue Mar 19 08:31:59 GMT 2024

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

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

Back to the top