tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Barry Dunne" <>
Subject Re: jar's still not picked up in WEB-INF/lib
Date Mon, 09 Oct 2000 05:47:43 GMT
Thanks for that, I have been trying to get a test case that shows this and 
have narrowed down the problem as follows....

If we have this calling structure:

Servlet s1
Class c1 in package p1 in jar j1
Class c2 in package p2 in jar j2

s1 calls c1.doSomething(),
c1.doSomething() calls c2.doSomethingElse()

Then there are a number of different ways the files can be located:
(the test results are with tomcat 4.0m1)

A) this works:


B) this works:


C) this works:


D) this works:


E) this works:


F) this works:


G) this FAILS:


H) this FAILS:


I) this works:


As this shows, G and H fail but all other combinations work.

To give some more detail as to what I am doing here, I am running EJB's in 
Oracle 8i and using servlets to communicate with them.

Originally I was using tomcat 3.1 and my web application used several jar 
files, 1 for my classes and other 3rd party ones (including the Oracle 
aurora naming jar).

I wanted to use case E but with tomcat 3.1 I got class not found exceptions, 
so I ended up putting the 3rd party jars in tomcat/lib and expanding my own 
jar into WEB-INF/classes - i.e. case G.
This worked but was not ideal.

So with tomcat 3.1 case E failed and G worked.

When I tried different versions I was testing case H, which as far as I can 
tell does not work on any version.

The big difference now though is that after testing I have found that what I 
originally wanted to do, case E, will work so I am happy now.

I hope you followed all that, apologies if it is not clear, it is now 5:45am 
and I am quite tired having been doing this stuff for way too long now.


From: "Craig R. McClanahan" <>
Subject: Re: jar's still not picked up in WEB-INF/lib
Date: Sun, 08 Oct 2000 19:23:54 -0700

Barry Dunne wrote:

 > This problem has been posted so many times for different versions of 
 > but it is still there.
 > To summarise the problem, if you put a jar file into WEB-INF/lib you get 
 > 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 
 > 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 
(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 
 > 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 
beasts, and one of the flaws of most implementations is that you don't get 
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 
(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 
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 
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 
of them leads to the same symptom:  ClassNotFoundException.

You can help us narrow these things down by being tediously specific in 
reports.  If you can create a small WAR file that reproduces the problem, 
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

Get Your Private, Free E-mail from MSN Hotmail at

Share information about yourself, create your own public profile at

View raw message