DynamicJAXBContextFactory.createContextFromXSD fails to load SchemaMetadata https://www.eclipse.org/forums/index.php/mv/msg/645100/1241023/#msg_1241023
I'm using the DynamicJAXBContextFactory.createContextFromXSD method to create a jaxbcontext from an xsd.

It works find when I instansiate all classes from a junit test, but when I call the same classes deployed on a glassfish 4 server, the class org.eclipse.persistence.jaxb.dynamic.metadata.SchemaMetadata can't be found!
Running GlassFish Server Open Source Edition 4.0 (build 89) with Eclipselink 2.5.0
I have tested with nightly build glassfish-4.0.1-b04-02_04_2014-ml with Eclipselink 2.5.1, it's the same fault there.

I downloaded the sourcecode and during debug I could set a log.debugflag to 4 and got a detailed description of the cause:

java.lang.ClassNotFoundException: *** Class 'org.eclipse.persistence.jaxb.dynamic.metadata.SchemaMetadata' was not found because bundle org.eclipse.persistence.core [211] does not import 'org.eclipse.persistence.jaxb.dynamic.metadata' even though bundle org.eclipse.persistence.moxy [216] does export it. Additionally, the class is also available from the system class loader. There are two fixes: 1) Add an import for 'org.eclipse.persistence.jaxb.dynamic.metadata' to bundle org.eclipse.persistence.core [211]; imports are necessary for each class directly touched by bundle code or indirectly touched, such as super classes if their methods are used. 2) Add package 'org.eclipse.persistence.jaxb.dynamic.metadata' to the 'org.osgi.framework.bootdelegation' property; a library or VM bug can cause classes to be loaded by the wrong class loader. The first approach is preferable for preserving modularity. ***

I added 'org.eclipse.persistence.jaxb.dynamic.metadata' to the 'org.osgi.framework.bootdelegation' property;
then the class loaded, but now it't can't find the constructor!

I debug the org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getConstructorFor method, (see code below), but it can't find the constructor even if they looks the same to me!
The parameterType is class org.eclipse.persistence.dynamic.DynamicClassLoader
the argType is class org.eclipse.persistence.dynamic.DynamicClassLoader
but somehow the methods parameterType.isAssignableFrom(argType)) && (!argType.isAssignableFrom(parameterType) fails if the code runs i glassfish 4 but works if run from a junit-test.

I don't know why it don't work, can someone help me please?

And the detailed message suggest that the number 1) sulotion should be used, i.e
1) Add an import for 'org.eclipse.persistence.jaxb.dynamic.metadata' to bundle org.eclipse.persistence.core [211];
Is this a bug in eclipselink, if so can someone fix it?

]]>Greger Sernemar2014-02-07T11:08:32-00:00Re: DynamicJAXBContextFactory.createContextFromXSD fails to load SchemaMetadata https://www.eclipse.org/forums/index.php/mv/msg/645100/1243277/#msg_1243277
For this feature MOXy leverages code from the JAXB reference implementation. Part of the code that is responsible for generating Java classes from an XML Schema. This code gave us problems when we tried to OSFi-ify it, therefore we couldn't expose the code that depended on it though OSGi.
]]>Blaise Doughan2014-02-10T19:30:59-00:00