tapestry classloading problems on JBoss

I am in the process of converting the presentation layer which is part of equanda to use tapestry5.

It all started with serious problems getting an ear with both a EJB3 jar and a tapestry5 war deployed and running. Having finally fixed that (by actually splitting out the tapestry stuff and deploying that separately, I ran into classloading troubles again.

Exception in method myapp.pages.SomethingEdit.onActivate(be.synergetics.ca.om.client.Competency) (at CompetencyEdit.java:47), parameter #1: No ClassLoaders found for: myapp.Something

No ClassLoaders found for: myapp.Something
Stack trace
        * org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:212)
        * org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:521)
        * org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:415)
        * java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        * java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        * java.lang.Class.forName0(Native Method)
        * java.lang.Class.forName(Class.java:164)
        * org.apache.tapestry.internal.services.ComponentEventImpl.coerceContext(ComponentEventImpl.java:82)
        * myapp.pages.SomethingEdit.handleComponentEvent(CompetencyEdit.java)

Taking a close look at the given stacktrace reveals the problem. The code seems to use Class.forName. This is not good in JBoss. That is, you can, but then you have to pass the classloader to use, and that has to be be the context classloader.
I have scanned the tapestry5 codebase and there is only one occurence of “Class.forName” which has no classloader specified, in the “ComponentEventImpl” class. The code was
Class desiredType = Class.forName(desiredTypeName);

Replacing this with
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if ( loader == null ) loader = this.getClass().getClassLoader();
Class desiredType = Class.forName(desiredTypeName, true, loader);

fixes the problem…

Leave a Reply

Your email address will not be published. Required fields are marked *

question razz sad evil exclaim smile redface biggrin surprised eek confused cool lol mad twisted rolleyes wink idea arrow neutral cry mrgreen