Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JAXBContextFactory Not Found
JAXBContextFactory Not Found [message #642854] Fri, 03 December 2010 00:41 Go to next message
Shelli Orton is currently offline Shelli OrtonFriend
Messages: 101
Registered: September 2009
Senior Member
Hi,

I wrote a webservice that has some data model classes and I'm using JAXB to generate the XML from those classes in the responses. Initially the model classes were part of the webservice project and included in the war in the WEB-INF/classes directory. I want to be able to reuse the model classes for my client code, so I refactored them out into a separate project that builds a jar that the webservice project now depends on.


Initially I had a jaxb.properties file in my war project classpath which I moved it to the jar file project as well. It has this entry:

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory


I'm deploying to Glassfish v3 which is supposed to use EclipseLink as its JAXB implementation by default.

The problem is when I deploy the war with the model classes jar, I get this exception:

javax.ws.rs.WebApplicationException: javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.ClassNotFoundException: org.eclipse.persistence.jaxb.JAXBContextFactory]
	at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:151)

It doesn't seem to matter if I have a jaxb.properties file in my classpath or not (I've added it to the war, jar and neither).

I'm using Maven so my initial war pom.xml had this dependency:
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.2.0-SNAPSHOT</version>            
        <scope>provided</scope>
    </dependency>

When I created the jar project I included the dependency in its pom.xml and removed it from the war's. When that didn't work, I added it back into the war's but still get the same error.

I'm so confused. Since the dependency is "provided" it's never included in the war regardless of which project pom its in. It shouldn't make a difference to how Glassfish finds it, should it?

Any advice on this is greatly appreciated as I have no ideas what could be causing the problem.

Thanks!
Re: JAXBContextFactory Not Found [message #642971 is a reply to message #642854] Fri, 03 December 2010 15:00 Go to previous messageGo to next message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
Registered: July 2009
Senior Member

Hi,

The jaxb.properties file should be included with and in the same package as the domain classes.

By default GlassFish uses the Metro JAXB implemention, Metro is the JAXB reference implementation. GlassFish contains EclipseLink's core and JPA components, but does not yet include the MOXy and SDO components. However you can add the MOXy bundle yourself from:

- http://www.eclipse.org/eclipselink/downloads/

Unfortunately, currently the JAX-WS implementation in GlassFish is hard coded to use the Metro JAXB implementation. Once you solve your current configuration issue, you will get to the point where you see a ClassCastException from the JAX-WS layer when you try to use MOXy JAXB.

Alternatively MOXy can be used as the binding layer with Jersey (JAX-RS) in GlassFish. For an example see:

- http://wiki.eclipse.org/EclipseLink/Examples/REST

-Blaise
Re: JAXBContextFactory Not Found [message #643011 is a reply to message #642971] Fri, 03 December 2010 16:17 Go to previous messageGo to next message
Shelli Orton is currently offline Shelli OrtonFriend
Messages: 101
Registered: September 2009
Senior Member
Hi,

So, when it was working with the model classes as part of the war project, it must have been using Metro JAXB? Nothing against MOXy, but if I don't need to add it to Glassfish and can use Metro instead I think that's the way I'd like to go just because it's less configuration. Is there a compelling reason to use MOXy?

Thanks!
Re: JAXBContextFactory Not Found [message #643064 is a reply to message #642854] Fri, 03 December 2010 20:40 Go to previous messageGo to next message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
Registered: July 2009
Senior Member

Hi,

Both MOXy and Metro implement the JAXB specification. MOXy contains many useful extensions:

XPath Based Mapping

MOXy's XPath based mapping extesnion offers true meet-in-the-middle mapping:

- http://bdoughan.blogspot.com/2010/09/xpath-based-mapping-geo code-example.html
- http://bdoughan.blogspot.com/2010/07/xpath-based-mapping.htm l

Externalized Mapping File

As an alternative to annotations, MOXy allows you to represent you metadata as an XML file:

- http://wiki.eclipse.org/EclipseLink/Examples/MOXy/EclipseLin k-OXM.XML

JPA Entity Support

Leveraging our JPA knowledge, MOXy contains a number of extensions for mapping JPA entities to XML:

- http://wiki.eclipse.org/EclipseLink/Examples/MOXy/JPA
- http://bdoughan.blogspot.com/2010/07/jpa-entities-to-xml-bid irectional.html

-Blaise

Re: JAXBContextFactory Not Found [message #643400 is a reply to message #643064] Mon, 06 December 2010 18:26 Go to previous message
Shelli Orton is currently offline Shelli OrtonFriend
Messages: 101
Registered: September 2009
Senior Member
Thanks Blaise for the very useful information, as always.

Smile
Previous Topic:Using Extensions for Schema Generation
Next Topic:Property field not updated UNLESS 1st initialised
Goto Forum:
  


Current Time: Fri Apr 26 11:58:22 GMT 2024

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

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

Back to the top