You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Tait E Larson <te...@us.ibm.com> on 2002/07/17 19:56:24 UTC

explicit ordering of jars searched by classloader in web application

I've got three third party jar files in the WEB-INF/lib directory of my web
aplication that  contain different versions of the same classes.  I need to
explicitly state the order in which the classloader searches these jars in
order for my web application to work correctly.   Can this be done by
manipulating the classloader at runtime? Would it be possible to explicitly
state the jar ordering somewhere in web.xml?

Thanks,

Tait



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: explicit ordering of jars searched by classloader in web application

Posted by Will Hartung <wi...@msoft.com>.
From: "Tait E Larson" <te...@us.ibm.com>
Sent: Wednesday, July 17, 2002 10:56 AM
Subject: explicit ordering of jars searched by classloader in web
application


> I've got three third party jar files in the WEB-INF/lib directory of my
web
> aplication that  contain different versions of the same classes.  I need
to
> explicitly state the order in which the classloader searches these jars in
> order for my web application to work correctly.   Can this be done by
> manipulating the classloader at runtime? Would it be possible to
explicitly
> state the jar ordering somewhere in web.xml?

Wow! That's certainly a issue that's fraught with peril.

Depending on how the container is written, it could be placing the jars in
the lib directory in a couple of different orders. They could be in
alphabetical order, or they could be in directory order (i.e. the order they
show up in an unsorted directory).

The Servlet Spec doesn't have anything about ordering the jars in lib
directory, so while a container can offer some specific information, it
won't be portable to another container. You certainly shouldn't rely on the
system directory layout itself, as that could change by simply reloading the
directory, or from platform to platform.

The BEST solution would be to pull the jars apart and build a single
"correct" jar that is not dependent upon the classpath load order. The
easiest way to do this would be to simply unjar them in "reverse classpath
order", so that whatever you want search first is unjarred last.

For example:

$ mkdir newjar
$ cd newjar
$ jar xf /path/to/3rdPartyLibOriginal.jar
$ jar xf /path/to/3rdPartyLibServicePack1.jar
$ jar xf /path/to/3rdPartyLibServicePack2.jar
$ jar cf /path/to/Integrated3rdPartyLib.jar .

Basically, this lets the latter jars overwrite the same named classes from
the earlier jars, and has the same effect as placing them before one another
in a classpath.

The other solution is to put them on the system classpath in the order
desired, but then they're not in the webapp WAR file.

Regards,

Will Hartung
(willh@msoft.com)




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: explicit ordering of jars searched by classloader in web application

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 17 Jul 2002, Tait E Larson wrote:

> Date: Wed, 17 Jul 2002 10:56:24 -0700
> From: Tait E Larson <te...@us.ibm.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: tomcat-user@jakarta.apache.org
> Subject: explicit ordering of jars searched by classloader in web
>     application
>
> I've got three third party jar files in the WEB-INF/lib directory of my web
> aplication that  contain different versions of the same classes.  I need to
> explicitly state the order in which the classloader searches these jars in
> order for my web application to work correctly.   Can this be done by
> manipulating the classloader at runtime? Would it be possible to explicitly
> state the jar ordering somewhere in web.xml?
>

If there was such a configuration option (and there's not) it would be
defined in the Servlet Specification
<http://java.sun.com/products/servlet/download.html>.

The only promise you get is that classes in "WEB-INF/classes" will be
loaded in preference to classes from JAR files in "WEB-INF/lib".  For the
individual JAR files in "WEB-INF/lib" directory, that is totaly up to the
container (and may not even be in the container's control if you run your
webapp from an open directory the way that Tomcat lets you do it).

IMHO, application designs that rely on this kind of thing are incredibly
fragile, because they rely on this sort of an internal detail.  I'd look
for libraries that let you configure which implementation of a particular
API you want (for example, the way that JAXP APIs let you configure which
parser implementation to use) instead.

> Thanks,
>
> Tait

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>