You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by niv the tool <ni...@wapcominc.com> on 2001/06/24 10:07:57 UTC

***ANOTHER TOMCAT CLASSPATH BUG***

Very simple to simulate this bug :

When adding c:\java\my-web-app-dir\web-inf\classes to CLASSPATH
Tomcat is loosing the jars in my c:\java\my-web-app-dir\web-inf\lib 


Ok now if ur asking why do I need it it so the answer is soap

I have a soap 2_2 context that needs to load a class in 
c:\java\my-web-app-dir\web-inf\classes


The only thing I manage to make this situation to work 
Is to put all my jars and myweb-inf\classes in the SYSTEM
CLASSPATH

But then I need to maintain this CLASSPATH when ever I am adding a new 
Jar file 


So Thanks in Advance

Niv the tool.


Re: ***ANOTHER TOMCAT CLASSPATH BUG***

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Carl Rosenberger wrote:
> 
> Geir Magnusson wrote:
> > > > > > When adding c:\java\my-web-app-dir\web-inf\classes to CLASSPATH
> > > > > > Tomcat is loosing the jars in my
> c:\java\my-web-app-dir\web-inf\lib
> > > > >
> > > > > Two workarounds were possible:
> > > > > - ..\project-dir\web-inf\classes added to the CLASSPATH
> > > > > - placing all Jars in ..\project-dir\web-inf\lib
> >
> > The reason is that you want to be able to partition your applications in
> > the servlet runner, to avoid classname clashes (each webapp can have
> > their own classes w/o worrying if another webapp uses the same
> > classname).  It also means that support packages, like jdbc drivers and
> > other utilities your webapp may use can be upgraded or changed for one
> > webapp w/o affecting any others.
> 
> Thanks a lot for this excellent explanation. You changed my opinion. It's
> not a bug, it's a feature. :-)

It is by design.  However, the 'look up' or 'delegate, then find' 
aspect can be problematic.  It comes from standard Java classloader
behavior, motivated in part by security - it prevents a classloader
below you from replacing something from the JDK, for example.

I believe that in the Servlet 2.3 spec (Tomcat 4 is the RI), the
classloader behavior is modified in the case of webapps.  I think it's
'find, then delegate' model.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

Re: ***ANOTHER TOMCAT CLASSPATH BUG***

Posted by Carl Rosenberger <ca...@db4o.com>.
Geir Magnusson wrote:
> > > > > When adding c:\java\my-web-app-dir\web-inf\classes to CLASSPATH
> > > > > Tomcat is loosing the jars in my
c:\java\my-web-app-dir\web-inf\lib
> > > >
> > > > Two workarounds were possible:
> > > > - ..\project-dir\web-inf\classes added to the CLASSPATH
> > > > - placing all Jars in ..\project-dir\web-inf\lib
>
> The reason is that you want to be able to partition your applications in
> the servlet runner, to avoid classname clashes (each webapp can have
> their own classes w/o worrying if another webapp uses the same
> classname).  It also means that support packages, like jdbc drivers and
> other utilities your webapp may use can be upgraded or changed for one
> webapp w/o affecting any others.

Thanks a lot for this excellent explanation. You changed my opinion. It's
not a bug, it's a feature. :-)

Kind regards,
Carl
---
Carl Rosenberger
db4o - database for objects - http://www.db4o.com



Re: ***ANOTHER TOMCAT CLASSPATH BUG***

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Carl Rosenberger wrote:
> 
> > > > When adding c:\java\my-web-app-dir\web-inf\classes to CLASSPATH
> > > > Tomcat is loosing the jars in my c:\java\my-web-app-dir\web-inf\lib
> > >
> > > Two workarounds were possible:
> > > - ..\project-dir\web-inf\classes added to the CLASSPATH
> > > - placing all Jars in ..\project-dir\web-inf\lib
> > >
> >
> > Isn't this due to how the classloaders work in a servlet container?
> > Classloaders in Servlet 2.2 spec containers don't look down for classes,
> > they look 'up'.  So a class in WEB-INF/lib won't be found by a class
> > instantiated in an upper level loader.
> 
> Thanks for explaining how servlet classloaders work.

That's just a sketch.  I am not an expert :)

> 
> Do you have more information on the reason for this beviour? Why not use one
> single classloader to be responsible for all levels? Is this a performance
> issue? Would it take the classloader too long to scan all paths in all
> directories for all possible classes that might be needed to work together?
> In this case some intelligent caching could do the trick.

The reason is that you want to be able to partition your applications in
the servlet runner, to avoid classname clashes (each webapp can have
their own classes w/o worrying if another webapp uses the same
classname).  It also means that support packages, like jdbc drivers and
other utilities your webapp may use can be upgraded or changed for one
webapp w/o affecting any others.

That's why I keep everying I possibly can in WEB-INF/lib - along with
the ability to jar up the webapp for easy deployment, I know I am safe
from changes to the CLASSPATH or other webapps.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

RE: ***ANOTHER TOMCAT CLASSPATH BUG***

Posted by niv the tool <ni...@wapcominc.com>.
Let me rephrase 

I have 2 contexts in tomcat 
1. my-web-app context
2. soap_2_2 context

In order for context2 to see my context 1 classes I must add
/my-web-app-dir/web-inf/classes
To the CLASSPATH

Adding this makes context 1 not to see the jars in
/my-web-app-dir/web-inf/lib


Weird isn't it


Re: ***ANOTHER TOMCAT CLASSPATH BUG***

Posted by Carl Rosenberger <ca...@db4o.com>.
> > > When adding c:\java\my-web-app-dir\web-inf\classes to CLASSPATH
> > > Tomcat is loosing the jars in my c:\java\my-web-app-dir\web-inf\lib
> >
> > Two workarounds were possible:
> > - ..\project-dir\web-inf\classes added to the CLASSPATH
> > - placing all Jars in ..\project-dir\web-inf\lib
> >
>
> Isn't this due to how the classloaders work in a servlet container?
> Classloaders in Servlet 2.2 spec containers don't look down for classes,
> they look 'up'.  So a class in WEB-INF/lib won't be found by a class
> instantiated in an upper level loader.

Thanks for explaining how servlet classloaders work.

Do you have more information on the reason for this beviour? Why not use one
single classloader to be responsible for all levels? Is this a performance
issue? Would it take the classloader too long to scan all paths in all
directories for all possible classes that might be needed to work together?
In this case some intelligent caching could do the trick.

Kind regards,
Carl
---
Carl Rosenberger
db4o - database for objects - http://www.db4o.com



Re: ***ANOTHER TOMCAT CLASSPATH BUG***

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Carl Rosenberger wrote:
> 
> > When adding c:\java\my-web-app-dir\web-inf\classes to CLASSPATH
> > Tomcat is loosing the jars in my c:\java\my-web-app-dir\web-inf\lib
> 
> Hi Niv,
> 
> we have also spent 2 days last week to debug this problem, since a user of
> our object database had problems to get in running.
> 
> The setup:
> The jar of our engine was registered in the global CLASSPATH. The user had
> his classes in ..\project-dir\web-inf\classes (not in the CLASSPATH). The
> phenomena was very interesting:
> The classes would work O.K. but our engine got a ClassNotFoundException
> calling Class.forName() for all web-inf\classes when it was invoked from the
> init() of the servlet.
> 
> Two workarounds were possible:
> - ..\project-dir\web-inf\classes added to the CLASSPATH
> - placing all Jars in ..\project-dir\web-inf\lib
> 
> Maybe the second solution might work our for you.
> 
> I would also consider the behaviour to be a Tomcat bug.

Isn't this due to how the classloaders work in a servlet container?
Classloaders in Servlet 2.2 spec containers don't look down for classes,
they look 'up'.  So a class in WEB-INF/lib won't be found by a class
instantiated in an upper level loader.

That's why it works when you put everyting in WEB-INF/lib or put
/classes in teh CLASSPATH, as that makes everything accessable to the
top-level loader.

IMHO, putting things in WEB-INF/lib is the best way, as that makes your
webapp more portable - it doesn't depend upon the CLASSPATH (which is
evil :).  

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

RE: ***ANOTHER TOMCAT CLASSPATH BUG***

Posted by niv the tool <ni...@wapcominc.com>.
Since we both consider it to be a tomcat bug 
I hope that one of tomcat guru will treat and answer this behavior

But I still cant understand why by putting my web-inf/classes in
CLASSPATH
Makes tomcat fail to find the web-inf/lib

-----Original Message-----
From: Carl Rosenberger [mailto:carl@db4o.com] 
Sent: Sunday, June 24, 2001 1:10 PM
To: tomcat-user@jakarta.apache.org
Subject: Re: ***ANOTHER TOMCAT CLASSPATH BUG***


> When adding c:\java\my-web-app-dir\web-inf\classes to CLASSPATH Tomcat

> is loosing the jars in my c:\java\my-web-app-dir\web-inf\lib

Hi Niv,

we have also spent 2 days last week to debug this problem, since a user
of our object database had problems to get in running.

The setup:
The jar of our engine was registered in the global CLASSPATH. The user
had his classes in ..\project-dir\web-inf\classes (not in the
CLASSPATH). The phenomena was very interesting: The classes would work
O.K. but our engine got a ClassNotFoundException calling Class.forName()
for all web-inf\classes when it was invoked from the
init() of the servlet.

Two workarounds were possible:
- ..\project-dir\web-inf\classes added to the CLASSPATH
- placing all Jars in ..\project-dir\web-inf\lib

Maybe the second solution might work our for you.

I would also consider the behaviour to be a Tomcat bug.


Kind regards,
Carl
---
Carl Rosenberger
db4o - database for objects - http://www.db4o.com


Re: ***ANOTHER TOMCAT CLASSPATH BUG***

Posted by Carl Rosenberger <ca...@db4o.com>.
> When adding c:\java\my-web-app-dir\web-inf\classes to CLASSPATH
> Tomcat is loosing the jars in my c:\java\my-web-app-dir\web-inf\lib

Hi Niv,

we have also spent 2 days last week to debug this problem, since a user of
our object database had problems to get in running.

The setup:
The jar of our engine was registered in the global CLASSPATH. The user had
his classes in ..\project-dir\web-inf\classes (not in the CLASSPATH). The
phenomena was very interesting:
The classes would work O.K. but our engine got a ClassNotFoundException
calling Class.forName() for all web-inf\classes when it was invoked from the
init() of the servlet.

Two workarounds were possible:
- ..\project-dir\web-inf\classes added to the CLASSPATH
- placing all Jars in ..\project-dir\web-inf\lib

Maybe the second solution might work our for you.

I would also consider the behaviour to be a Tomcat bug.


Kind regards,
Carl
---
Carl Rosenberger
db4o - database for objects - http://www.db4o.com