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 01:56
Jens Offenbach is currently offline Jens Offenbach
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(JaxbClassLoader.java:110)
	at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.generateWrapperClass(MappingsGenerator.java:3226)
	at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.generateWrapperClassAndDescriptor(MappingsGenerator.java:2995)
	at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.addEnumerationWrapperAndDescriptor(MappingsGenerator.java:2966)
	at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.processGlobalElements(MappingsGenerator.java:2913)
	at org.eclipse.persistence.jaxb.compiler.MappingsGenerator.generateProject(MappingsGenerator.java:275)
	at org.eclipse.persistence.jaxb.compiler.Generator.generateProject(Generator.java:188)
	at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:1064)
	at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:1056)
	at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:182)
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:165)
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:152)
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:112)
	at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:102)


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: Wed Jul 23 04:08:28 EDT 2014

Powered by FUDForum. Page generated in 0.02189 seconds