Sahoo,
Thanks!
Once again, you've rescued me. That workaround will do for now. I've voted for the issue, and will be anxiously awaiting its fix.
Larry
From: Sanjeeb.Sahoo_at_Sun.COM [mailto:Sanjeeb.Sahoo_at_Sun.COM] On Behalf Of Sanjeeb Sahoo
Sent: Friday, June 04, 2010 1:26 PM
To: users_at_glassfish.dev.java.net
Subject: Re: JAXB in Glassfish
Larry,
I have actually filed a bug for this. See [1]. Vote for it please. I don't know if there is any better way to solve it, but I faced it for one of my GlassFish extension bundles and I worked around it like this:
import org.glassfish.internal.api.Globals;
import org.glassfish.internal.api.ClassLoaderHierarchy;
...
private JAXBContext getJAXBContext() throws JAXBException {
// We need to set context class loader to be CommonClassLoader, otherwise our stupid JAXB implementation
// won't be able to locate the default JAXB context factory class.
final Thread thread = Thread.currentThread();
ClassLoader oldCL = thread.getContextClassLoader();
try {
ClassLoader ccl = Globals.get(ClassLoaderHierarchy.class).getCommonClassLoader();
thread.setContextClassLoader(ccl);
JAXBContext jc = JAXBContext.newInstance(ObjectFactory.class);
return jc;
} finally {
thread.setContextClassLoader(oldCL);
}
}
You will have to add the following dependency to compile though:
<dependency>
<groupId>org.glassfish.common</groupId>
<artifactId>internal-api</artifactId>
<version>${project.version}</version>
</dependency>
I don't think you can apply this work around in your code - it has too much dependency on glassfish internals.
Thanks,
Sahoo
[1]
https://glassfish.dev.java.net/issues/show_bug.cgi?id=11748