tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: jar's still not picked up in WEB-INF/lib
Date Mon, 09 Oct 2000 02:23:54 GMT
Barry Dunne wrote:

> This problem has been posted so many times for different versions of tomcat
> but it is still there.
> To summarise the problem, if you put a jar file into WEB-INF/lib you get a
> class not found exception when you try to use one of the classes from the
> jar in a servlet. However, this does not happen when you either move the jar
> to /usr/local/tomcat/lib or extract the jar into WEB-INF/classes.
> Neither of these workarounds are very nice, the former makes sharing a
> server between multiple contexts/developers tricky and the latter makes a
> mess of the classes directory.
> There have been so many posts about this feature not working over time and I
> have had the problem myself on linux with tomcat 3.1, 3.2 and now 4.0m1.

You will find that there are three fairly different classloader implementations
(the 4.0m1 implemenation is 100% different) on these three versions -- it
certainly is not the same bug just being carried forward.

> This is a pretty fundemental flaw as the lib is a fairly significant part of
> the specifications to be able to use WEB-INF/lib.
> Does anybody know why this problem has been left for so long now?
> Thanks,
> Barry.

The problem is that it is not just one "problem".  Classloaders are intricate
beasts, and one of the flaws of most implementations is that you don't get much
evidence of what's really going on when they return ClassNotFoundException.

As others have reported, putting JAR files in WEB-INF/lib works for most people
(but not all) under 3.2b and 4.0m1 (3.1 has problems in this area that were
addressed in 3.2).  Here's a partial list of the kinds of problems that will
cause it to fail.

* Having a JAR file in *both* WEB-INF/lib and on your classpath

* Having a JAR file in *both* WEB-INF/lib and the system extensions
  classpath ($JAVA_HOME/jre/lib/ext).

* Having a class library that is on the class path and (from a
  class in that class library) trying to reference a class in the
  WEB-INF/lib area -- it's not accessible.  (This is why the
  "struts.jar" file for Struts *must* be in WEB-INF/lib and *not*
  on the classpath, for example).

* User error in untold varieties:
  - Putting ZIP files instead of JAR files in WEB-INF/lib
  - Forgetting to put the JAR file there
  - Corrupted JAR file (it will be *silently* ignored)
  - JAR file that doesn't really have the class you think it has
  - Operating system permissions problems

Given how many people have trouble getting CLASSPATHs for Java applications and
compilation right, it's not certainly an issue that is not unique to Tomcat.

The challenge is to narrow down, in every single circumstance, exactly what is
going on.  The requires knowing all of the following facts:
* OS and JDK versions
* If a Java2 platform, what do you have installed as system
* What is on your CLASSPATH (not an issue for Tomcat 4.0m1,
  which totally ignores it)?
* What libraries do you have in your $TOMCAT_HOME/lib or
  $CATALINA_HOME/lib directory?
* What libraries do you have in your WEB-INF/lib directory?
* Where was the class that threw the ClassNotFoundException
  loaded from?
* Where was the class that wasn't found supposed to be loaded

As you can see, there are many possibilities for having a problem -- and any one
of them leads to the same symptom:  ClassNotFoundException.

You can help us narrow these things down by being tediously specific in error
reports.  If you can create a small WAR file that reproduces the problem, that
is absolutely the best tool for resolving things like this.

Craig McClanahan

See you at ApacheCon Europe <>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat

View raw message