You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Dennis Murphy <dm...@seas.upenn.edu> on 2001/06/22 18:57:32 UTC
JDK CLASSPATH vs TOMCAT CLASSPATH
Hi,
I'm new to JSP.
I desire to use the class reloadable="YES" feature in TOMCAT so that I
can develop my JAVA BEANS and quickly test them without restarting
TOMCAT for every little change.
I believe that the reloadable feature will not work if I inform the
system CLASSPATH where my JSP application classes are located. The
reason for this is that the once the SYSTEM CLASS LOADER loads my
classes the TOMCAT CLASSLOADER has no control and is unable to
unload/reload my classes.
Okay if I'm right on my understanding of this, then how do you setup a
development environment. In order for me to compile my JAVA BEANS using
JDK javac, I must tell JDK where my classes are located in the SYSTEM
CLASS PATH ... else it won't be able to pickup my custom packages that
are part of my application.
So is this like a trade-off? Compile JAVA BEANS or use the TOMCAT class
reloading feature - but not both?
Can someone please shed some light on how one should setup a development
environment? I would like to have the ability to compile and then test
with tomcat configured to reload classes.
Thank you,
Dennis
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
***ANOTHER TOMCAT CLASSPATH BUG***
Posted by niv the tool <ni...@wapcominc.com>.
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: JDK CLASSPATH vs TOMCAT CLASSPATH
Posted by Dennis Murphy <dm...@seas.upenn.edu>.
Hey There!
I did learn more stuff.
What had happened is that along the way I explicitly added WEB-INF/classes to my
TOMCAT path in my tomcat.bat file. I figured this would be harmless. But I
guess it does effect CLASS RELOADING.
Therefore, I found if you want CLASS RELOADING to work DO NOT place your
WEB-INF/classes path in the system CLASSPATH or explicitly in the
TOMCAT_CLASSPATH.
Wow! I took me all day to get this working :-(
Dennis
Dennis Murphy wrote:
> Hi Again,
>
> No one got back to me but I did learn a few things today:
>
> 1. No need to tell the system class path about the WEB-INF area. All I need
> to do is compile from WEB-INF/classes and JDK finds all of my custom
> packages. This is b/c by default . is added to JDK's path.
>
> 2. I think I know why TOMCAT can't find my classes. That's b/c I do not have
> a /WEB-INF/lib folder. I think this folder should contain the webapp class
> loader among other things.
>
> When I installed TOMCAT 3.2.1 out of the box - the examples webapp did not
> have a /WEB-INF/lib folder (unless I accidentally deleted it!).
>
> Question: Where do I download the required files for the /WEB-INF/lib
> folder? Or do I have to build them?
>
> Dennis
>
> Dennis Murphy wrote:
>
> > Hi,
> >
> > I'm new to JSP.
> >
> > I desire to use the class reloadable="YES" feature in TOMCAT so that I
> > can develop my JAVA BEANS and quickly test them without restarting
> > TOMCAT for every little change.
> >
> > I believe that the reloadable feature will not work if I inform the
> > system CLASSPATH where my JSP application classes are located. The
> > reason for this is that the once the SYSTEM CLASS LOADER loads my
> > classes the TOMCAT CLASSLOADER has no control and is unable to
> > unload/reload my classes.
> >
> > Okay if I'm right on my understanding of this, then how do you setup a
> > development environment. In order for me to compile my JAVA BEANS using
> > JDK javac, I must tell JDK where my classes are located in the SYSTEM
> > CLASS PATH ... else it won't be able to pickup my custom packages that
> > are part of my application.
> >
> > So is this like a trade-off? Compile JAVA BEANS or use the TOMCAT class
> > reloading feature - but not both?
> >
> > Can someone please shed some light on how one should setup a development
> > environment? I would like to have the ability to compile and then test
> > with tomcat configured to reload classes.
> >
> > Thank you,
> > Dennis
Re: JDK CLASSPATH vs TOMCAT CLASSPATH
Posted by Dennis Murphy <dm...@seas.upenn.edu>.
Hi Again,
No one got back to me but I did learn a few things today:
1. No need to tell the system class path about the WEB-INF area. All I need
to do is compile from WEB-INF/classes and JDK finds all of my custom
packages. This is b/c by default . is added to JDK's path.
2. I think I know why TOMCAT can't find my classes. That's b/c I do not have
a /WEB-INF/lib folder. I think this folder should contain the webapp class
loader among other things.
When I installed TOMCAT 3.2.1 out of the box - the examples webapp did not
have a /WEB-INF/lib folder (unless I accidentally deleted it!).
Question: Where do I download the required files for the /WEB-INF/lib
folder? Or do I have to build them?
Dennis
Dennis Murphy wrote:
> Hi,
>
> I'm new to JSP.
>
> I desire to use the class reloadable="YES" feature in TOMCAT so that I
> can develop my JAVA BEANS and quickly test them without restarting
> TOMCAT for every little change.
>
> I believe that the reloadable feature will not work if I inform the
> system CLASSPATH where my JSP application classes are located. The
> reason for this is that the once the SYSTEM CLASS LOADER loads my
> classes the TOMCAT CLASSLOADER has no control and is unable to
> unload/reload my classes.
>
> Okay if I'm right on my understanding of this, then how do you setup a
> development environment. In order for me to compile my JAVA BEANS using
> JDK javac, I must tell JDK where my classes are located in the SYSTEM
> CLASS PATH ... else it won't be able to pickup my custom packages that
> are part of my application.
>
> So is this like a trade-off? Compile JAVA BEANS or use the TOMCAT class
> reloading feature - but not both?
>
> Can someone please shed some light on how one should setup a development
> environment? I would like to have the ability to compile and then test
> with tomcat configured to reload classes.
>
> Thank you,
> Dennis