Skip to main content

Loader element of context supported in Glassfish 4.0?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
dheinecke
Offline
Joined: 2013-11-07

I am trying to migrate a custom set of webapps from tomcat to glassfish. The webapps all use a custom classloader to allow sharing of class instances between them (Think of heirarchical Spring bean factories). The way that we currently make this work is with a custom webapp classloader that we expose through the the context.xml:

<Context crossContext="true">
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <Manager pathname="" />
    <Loader loaderClass="com.xxx.xxx.core.server.OrionClassLoader"
            reloadable="false"
            delegate="false"/>
</Context>

Unfortunately, when I launch the root webapp, I get this exception:

[2013-11-06T09:35:15.019-0800] [glassfish 4.0] [SEVERE] [AS-WEB-CORE-00292] [javax.enterprise.web.core] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1383759315019] [levelValue: 1000] [[
LifecycleException
java.lang.ClassNotFoundException: com.xxx.xxx.core.server.OrionClassLoader not found by org.glassfish.main.web.core [261]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at org.apache.catalina.loader.WebappLoader.createClassLoader(WebappLoader.java:857)
at org.apache.catalina.loader.WebappLoader.start(WebappLoader.java:729)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5830)
at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2278)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1924)
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:139)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)

It looks like it almost, kinda works... but it looks like the root error is coming out of Felix and our webapp classloader is not in a bundle. I've tried putting the jar with the webapp classloader in as_install/lib, domains/domain1/lib, domains/domain1/applib and there is no difference in the error generated.

Two questions here: does anyone know if the Loader element is supposed to be supported in a glassfish context.xml? Secondly, might this work if I create a bundle with our classloader and register it?

I realize that the "correct" way to do this would be to re-write this using more standard means to enable sharing of objects between webapps, but we are trying to just get it working first, then refactor it to remove the customizations.

Thanks!