users@glassfish.java.net

[gf-users] Class Loading in GlassFish

From: Philippe Marschall <philippe.marschall_at_gmail.com>
Date: Mon, 6 Apr 2015 20:51:33 +0200

Hi

I'm putting together a presentation that compares class loading in
different Java application servers. From reading
"GlassFish Server Open Source Edition Application Development Guide
Release 4.0" [1] and some personal experiments with 4.1 full profile I
get the following picture:

Class loading is always "parent first", ie. considers the delegate
first. This includes the WEB-INF/class and WEB-INF/lib folders with
are considered only *after* the delegate. This is against the
recommendation in section 10.7.2 of the servlet specification but
still spec compliant.
The behavior can be changed to "parent last" with delegate="false" but
only if the application does not accesses EJB components and does not
act as a web service client or endpoint.
Even if the behavior is changed certain packages like java.* and
javax.* are always loaded via the delegate. Is the list of packages
available?

Among others following packages are visible to the application:
 - org.apache.jasper.*
 - org.apache.catalina.*

Among others the following libraries are visible to the application:

 - Gooble Guava (eg. com.google.common.collect.Maps)
 - Jettison (eg. org.codehaus.jettison.mapped.Configuration)
 - Mimepull (eg. org.jvnet.mimepull.MIMEMessage)
 - Apache Ant (eg. org.apache.tools.ant.Task)
 - Apache Tools (eg.apache.tools.tar.TarBuffer)
 - Woodstox (eg. com.ctc.wstx.stax.WstxInputFactory)

These are also loaded "parent first". This means that for example when
you package Google Guava in your web application you will instead get
the one from GlassFish (unless you use delegate="false"). Is my
understanding of this correct?

Neither org.glassfish.web.loader.WebappClassLoader nor
org.glassfish.internal.api.DelegatingClassLoader are parallel capable.

 [1] https://glassfish.java.net/docs/4.0/application-development-guide.pdf

Cheers
Philippe