tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: How to determine current search path?
Date Tue, 04 Sep 2001 23:47:28 GMT
On Tue, 4 Sep 2001, Rick Mann wrote:

> Date: Tue, 04 Sep 2001 15:42:07 -0700
> From: Rick Mann <>
> Reply-To:
> To: tomcat user <>
> Subject: How to determine current search path?
> For debugging purposes, is there a way to determine what class directories
> and jar files will be searched, and in what order, for a given context? I'm
> happy to insert code into a servlet or JSP to dump this information, but I
> want to be sure of the actual search path, considering all environment
> variable settings, class loader settings, etc.
> Is this possible? Is there a Java class that contains this information to
> which I can make this query?
> TIA,

In the general case, there is no perfect answer to this, but here's a
partial answer for containers (like Tomcat 4) that use as the basis for their web app class loader.

The key method calls are:

* URLClassLoader.getURLs() returns the repositories (directories and JAR
  files) that are searched by this class loader.

* ClassLoader.getParent() returns the parent class loader.

So, you can do something like this in a servlet:

  ClassLoader cl = this.getClass().getClassLoader();
  while ((cl != null) && (cl instanceof URLClassLoader)) {
    URL urls[] = ((URLClassLoader) cl).getURLs();
    ... dump out the string form of these urls ...
    cl = cl.getParent();

To determine the order, you need to be aware of the following:

* By default, Java class loaders delegate to the parent class loader
  *first*, then look locally.

* In a servlet 2.3 environment, the container is allowed to look
  locally in the web app class loader *before* delegating, and
  Tomcat 4 does this.

Craig McClanahan

View raw message