Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » [MOXy] NoClassDefFoundError within OSGi
[MOXy] NoClassDefFoundError within OSGi [message #1184018] Wed, 13 November 2013 06:56
Jens Offenbach is currently offline Jens OffenbachFriend
Messages: 1
Registered: November 2013
Junior Member
The problem is not easy to describe, but after some time of debugging I found the reason. I have a workaround, it would be nice, if a developer can evaluate if it should (or must) be fixed properly.

Basically it is a classloading problem within OSGi. I get the following exception:
Caused by: java.lang.NoClassDefFoundError: org/eclipse/persistence/internal/jaxb/WrappedValue
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(Unknown Source)
	at java.lang.ClassLoader.defineClass(Unknown Source)
	at org.eclipse.persistence.internal.jaxb.JaxbClassLoader.generateClass(
	at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.generateWrapperClass(
	at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.generateWrapperClassAndDescriptor(
	at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.addEnumerationWrapperAndDescriptor(
	at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.processGlobalElements(
	at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.generateProject(
	at org.eclipse.persistence.jaxb.compiler.Generator.generateProject(
	at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(
	at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(
	at org.eclipse.persistence.jaxb.JAXBContext.<init>(
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(

This is the problematic line in the class MappingsGenerator, line 3226:
Class generatedClass = getJaxbClassLoader().generateClass(className, classBytes);

The method getJaxbClassLoader() returns a wrapped classloader that is associated with my bundle. This classloader is used to define a dynamic generated class which uses the class org/eclipse/persistence/internal/jaxb/WrappedValue. My bundle only imports the package org.eclipse.persistence.jaxb. That causes the problem because my bundle classloader cannot load the required class org/eclipse/persistence/internal/jaxb/WrappedValue. Is there are reason why my classloader is used at this point? If you used the classloader of the MoXy bundle, everything would work. The problem can be solved by importing the specific package org/eclipse/persistence/internal/jaxb or for future problems by Require-Bundle which means that all packages of the moxy bundle are imported by my bundle and therefore accessible via my bundle classloader.

The problem is caused at the very beginning when I create a JAXBContext via the JAXBContextFactory without forwarding a classloader. You use the one associated with the first Class provided. This is the code (JAXBContextFactory, line: 99-101):
if (classesToBeBound.length > 0) {
   loader = classesToBeBound[0].getClassLoader();

This specific class is contained in my bundle and therefore this method returns the ClassLoader of my bundle which causes all these problems. I cannot find any documentation which classloader should be forwarded to the JAXBContextFactory.

What is your view of the problem?
Previous Topic:add list of entities
Next Topic:Aggregated objects cannot be written/deleted/queried independently from their owners
Goto Forum:

Current Time: Thu Apr 26 13:47:12 GMT 2018

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

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