You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Narahari 'n' Savitha <sa...@gmail.com> on 2013/01/17 15:20:51 UTC

common vs system vs shared class loaders

Friends:

Thank you for your time.

Here is the entry for the catalina.policy file



common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar

server.loader=

shared.loader=${catalina.home}/thirdPartyLib/*.jar,${catalina.home}/webServicesLib/*.jar


For example I have SpringBean entries in the web.xml


  <?xml version="1.0" encoding="utf-8"?>

<web-app id="WebApp_ID" version="2.5"

      xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"

      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

      <display-name>test/testing</display-name>



      <!-- Add Support for Spring -->

      <listener>


<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

      </listener>

      <listener>


<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>

      </listener>



The spring bean jars are in the thirdPartyLib folder.

The shared.loader line has the entries for the thirdPartyLib/*.jar and is
not getting picked up by the class loader.

I see ClassNotFoundExceptions in the localhost log file.



However when I appended the thirdPartyLib/*.jar to the line common.loader
line on my computer,  things started working.


What is the right approach ?    There is confusion inside our group as to
what is the right approach.


Should we use the common.loader line or the shared.loader line ?


I would like to hear from the Tomcat experts so we can do it the right way.


Regards,

-Narahari

Re: common vs system vs shared class loaders

Posted by Narahari 'n' Savitha <sa...@gmail.com>.
I could not have said better than Shanti.  It is exactly the type of
situation in.

My question still remains which line

common.loader

or

share.loader

-Narahari

On Thu, Jan 17, 2013 at 1:48 PM, Shanti Suresh <sh...@umich.edu> wrote:

> Hi Chuck, Dan,
>
> Sometimes, sharing classes across applications may become necessary
> though.  We have a situation where a separate application and associated
> webapp classloader is launched for each site in our application.  The
> reason this is happening is because things have been setup differently
> internally - without going into too many details.  So, we ran into PermGen
> exhaustion issues.  Putting all the libraries in $CATALINA_HOME/common/lib"
> and modifying the common classloader in catalina.properties as follows,
> ensures that a single copy of the classes get loaded and shared among all
> sites:
>
>
> common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,${catalina.base}/common/lib/*.jar
>
> We wanted to also put the libraries into a separate directory called
> "common/" because we wanted to keep them separate from the Tomcat-native
> libraries.
>
> He may have a similar situation too; don't know.
>
> Regards,
>
>                   -Shanti
>
>
> On Thu, Jan 17, 2013 at 10:58 AM, Daniel Mikusa <dm...@vmware.com>
> wrote:
>
> > On Jan 17, 2013, at 10:26 AM, Caldarale, Charles R wrote:
> >
> > >> From: Narahari 'n' Savitha [mailto:savithari@gmail.com]
> > >> Subject: Re: common vs system vs shared class loaders
> > >
> > >> Sorry Dan but if I do what you are suggesting I will end up in
> redundant
> > >> jars all over the place and I dont want to do that.
> > >
> > > That's an issue easily handled by a deployment script.  You really,
> > really, really do not want to share classes across webapps.
> > >
> > > - Chuck
> > >
> >
> > +1
> >
> > Dan
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
>

Re: common vs system vs shared class loaders

Posted by Mark Eggers <it...@yahoo.com>.
Comments in-line since people insist on top-posting.

Some at the end as well . . . .

On 1/17/2013 10:48 AM, Shanti Suresh wrote:
> Hi Chuck, Dan,
>
> Sometimes, sharing classes across applications may become necessary
> though.  We have a situation where a separate application and
> associated webapp classloader is launched for each site in our
> application.  The reason this is happening is because things have
> been setup differently internally - without going into too many
> details.  So, we ran into PermGen exhaustion issues.  Putting all the

Fix your web application, fix your libraries, and don't use libraries 
that cause PermGen leaks - they weren't properly designed for web 
applications in the first place.

There are many good articles on PermGen leaks on the web, what causes 
them, how to find them, and how to avoid them. Google is your friend.

> libraries in $CATALINA_HOME/common/lib" and modifying the common
> classloader in catalina.properties as follows, ensures that a single
> copy of the classes get loaded and shared among all sites:
>
> common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,${catalina.base}/common/lib/*.jar
>
>  We wanted to also put the libraries into a separate directory
> called "common/" because we wanted to keep them separate from the
> Tomcat-native libraries.
>
> He may have a similar situation too; don't know.
>

That being said, I have one library used by some applications that 
creates problems. It doesn't cause much of a leak, but over time it will 
create an issue. Unless I rewrite the vendor's code (tempting) or use a 
different library (also tempting), I'm stuck with this leak.

Probably the cleanest way to attack this problem (until you fix your 
code), is to run out of $CATALINA_BASE. Leave a default Tomcat as 
$CATALINA_HOME, and then put all of your misbehaving libraries in 
$CATALINA_BASE/lib.

See RUNNING.txt for how this works. We use this method to load JDBC 
drivers and mail.jar in certain instances of Tomcat, while leaving other 
instances of Tomcat 'bare'.

This still creates a nightmare (in my opinion) for software release 
management. You must ensure that all applications running on a 
particular infected Tomcat use the same version of the libraries placed 
in $CATALINA_BASE/lib.

This of course places the burden on operations and systems people rather 
than on developers. My personal opinion is that badly behaved 
applications should be taken care of by developers and not triaged by 
the systems people. However, I'm a systems person so I'm probably a bit 
biased in that regard.

Again - for PermGen leaks - fix your code.

> Regards,
>
> -Shanti
>
>
> On Thu, Jan 17, 2013 at 10:58 AM, Daniel Mikusa <dm...@vmware.com>
> wrote:
>
>> On Jan 17, 2013, at 10:26 AM, Caldarale, Charles R wrote:
>>
>>>> From: Narahari 'n' Savitha [mailto:savithari@gmail.com]
>>>> Subject: Re: common vs system vs shared class loaders
>>>
>>>> Sorry Dan but if I do what you are suggesting I will end up in
>>>> redundant jars all over the place and I dont want to do that.
>>>
>>> That's an issue easily handled by a deployment script.  You
>>> really,
>> really, really do not want to share classes across webapps.
>>>
>>> - Chuck
>>>
>>
>> +1
>>
>> Dan

Please folks, is not top-posting that difficult to understand? If you 
top-post, then I have to scroll up and down the message to figure out 
the context, and make sure that what I'm answering is:

a. The question being asked
b. Hasn't been answered in this fashion before
c. Fits all the constraints of the problem.

Doing so takes time. I participate here because I use Tomcat and hope to 
contribute back to the community. Top-posting creates an additional 
barrier which discourages contribution.

. . . . just my two cents.
/mde/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: common vs system vs shared class loaders

Posted by Shanti Suresh <sh...@umich.edu>.
Hi Chuck, Dan,

Sometimes, sharing classes across applications may become necessary
though.  We have a situation where a separate application and associated
webapp classloader is launched for each site in our application.  The
reason this is happening is because things have been setup differently
internally - without going into too many details.  So, we ran into PermGen
exhaustion issues.  Putting all the libraries in $CATALINA_HOME/common/lib"
and modifying the common classloader in catalina.properties as follows,
ensures that a single copy of the classes get loaded and shared among all
sites:

common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,${catalina.base}/common/lib/*.jar

We wanted to also put the libraries into a separate directory called
"common/" because we wanted to keep them separate from the Tomcat-native
libraries.

He may have a similar situation too; don't know.

Regards,

                  -Shanti


On Thu, Jan 17, 2013 at 10:58 AM, Daniel Mikusa <dm...@vmware.com> wrote:

> On Jan 17, 2013, at 10:26 AM, Caldarale, Charles R wrote:
>
> >> From: Narahari 'n' Savitha [mailto:savithari@gmail.com]
> >> Subject: Re: common vs system vs shared class loaders
> >
> >> Sorry Dan but if I do what you are suggesting I will end up in redundant
> >> jars all over the place and I dont want to do that.
> >
> > That's an issue easily handled by a deployment script.  You really,
> really, really do not want to share classes across webapps.
> >
> > - Chuck
> >
>
> +1
>
> Dan
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: common vs system vs shared class loaders

Posted by Narahari 'n' Savitha <sa...@gmail.com>.
The question that I am trying to understand is should I use the
common.loader
or
shared.loader

line to put my third party jars.

What is the recommended approach by Tomcat developers ?

-Narahari


On Thu, Jan 17, 2013 at 10:58 AM, Daniel Mikusa <dm...@vmware.com> wrote:

> On Jan 17, 2013, at 10:26 AM, Caldarale, Charles R wrote:
>
> >> From: Narahari 'n' Savitha [mailto:savithari@gmail.com]
> >> Subject: Re: common vs system vs shared class loaders
> >
> >> Sorry Dan but if I do what you are suggesting I will end up in redundant
> >> jars all over the place and I dont want to do that.
> >
> > That's an issue easily handled by a deployment script.  You really,
> really, really do not want to share classes across webapps.
> >
> > - Chuck
> >
>
> +1
>
> Dan
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: common vs system vs shared class loaders

Posted by Daniel Mikusa <dm...@vmware.com>.
On Jan 17, 2013, at 10:26 AM, Caldarale, Charles R wrote:

>> From: Narahari 'n' Savitha [mailto:savithari@gmail.com] 
>> Subject: Re: common vs system vs shared class loaders
> 
>> Sorry Dan but if I do what you are suggesting I will end up in redundant
>> jars all over the place and I dont want to do that.
> 
> That's an issue easily handled by a deployment script.  You really, really, really do not want to share classes across webapps.
> 
> - Chuck
> 

+1  

Dan
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: common vs system vs shared class loaders

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Narahari 'n' Savitha [mailto:savithari@gmail.com] 
> Subject: Re: common vs system vs shared class loaders

> Sorry Dan but if I do what you are suggesting I will end up in redundant
> jars all over the place and I dont want to do that.

That's an issue easily handled by a deployment script.  You really, really, really do not want to share classes across webapps.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: common vs system vs shared class loaders

Posted by Narahari 'n' Savitha <sa...@gmail.com>.
Sorry Dan but if I do what you are suggesting I will end up in redundant
jars all over the place and I dont want to do that.

Any other thoughts ?

On Thu, Jan 17, 2013 at 9:54 AM, Daniel Mikusa <dm...@vmware.com> wrote:

> On Jan 17, 2013, at 9:20 AM, Narahari 'n' Savitha wrote:
>
> > Friends:
> >
> > Thank you for your time.
> >
> > Here is the entry for the catalina.policy file
> >
> >
> >
> >
> common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar
> >
> > server.loader=
> >
> >
> shared.loader=${catalina.home}/thirdPartyLib/*.jar,${catalina.home}/webServicesLib/*.jar
> >
> >
> > For example I have SpringBean entries in the web.xml
> >
> >
> >  <?xml version="1.0" encoding="utf-8"?>
> >
> > <web-app id="WebApp_ID" version="2.5"
> >
> >      xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="
> > http://www.w3.org/2001/XMLSchema-instance"
> >
> >      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> > http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
> >
> >      <display-name>test/testing</display-name>
> >
> >
> >
> >      <!-- Add Support for Spring -->
> >
> >      <listener>
> >
> >
> >
> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
> >
> >      </listener>
> >
> >      <listener>
> >
> >
> >
> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
> >
> >      </listener>
> >
> >
> >
> > The spring bean jars are in the thirdPartyLib folder.
> >
> > The shared.loader line has the entries for the thirdPartyLib/*.jar and is
> > not getting picked up by the class loader.
> >
> > I see ClassNotFoundExceptions in the localhost log file.
> >
> >
> >
> > However when I appended the thirdPartyLib/*.jar to the line common.loader
> > line on my computer,  things started working.
> >
> >
> > What is the right approach ?    There is confusion inside our group as to
> > what is the right approach.
>
> My opinion, don't mess with either one.  Most Tomcat users should not need
> to change these values.  What is your reason for wanting to change these?
>
> >
> >
> > Should we use the common.loader line or the shared.loader line ?
>
> Leave them alone.  Don't touch either one.
>
> >
> >
> > I would like to hear from the Tomcat experts so we can do it the right
> way.
> >
>
> My suggestion would be to put JDBC drivers into "$CATALINA_BASE/lib" or
> "$CATALINA_HOME/lib" and put the rest of your JAR files in "WEB-INF/lib".
>  It's the simplest approach, it lets you easily hot redeploy your
> application and it cuts down on weird class loader issues.
>
> Dan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: common vs system vs shared class loaders

Posted by Daniel Mikusa <dm...@vmware.com>.
On Jan 17, 2013, at 9:20 AM, Narahari 'n' Savitha wrote:

> Friends:
> 
> Thank you for your time.
> 
> Here is the entry for the catalina.policy file
> 
> 
> 
> common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar
> 
> server.loader=
> 
> shared.loader=${catalina.home}/thirdPartyLib/*.jar,${catalina.home}/webServicesLib/*.jar
> 
> 
> For example I have SpringBean entries in the web.xml
> 
> 
>  <?xml version="1.0" encoding="utf-8"?>
> 
> <web-app id="WebApp_ID" version="2.5"
> 
>      xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance"
> 
>      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
> 
>      <display-name>test/testing</display-name>
> 
> 
> 
>      <!-- Add Support for Spring -->
> 
>      <listener>
> 
> 
> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
> 
>      </listener>
> 
>      <listener>
> 
> 
> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
> 
>      </listener>
> 
> 
> 
> The spring bean jars are in the thirdPartyLib folder.
> 
> The shared.loader line has the entries for the thirdPartyLib/*.jar and is
> not getting picked up by the class loader.
> 
> I see ClassNotFoundExceptions in the localhost log file.
> 
> 
> 
> However when I appended the thirdPartyLib/*.jar to the line common.loader
> line on my computer,  things started working.
> 
> 
> What is the right approach ?    There is confusion inside our group as to
> what is the right approach.

My opinion, don't mess with either one.  Most Tomcat users should not need to change these values.  What is your reason for wanting to change these? 

> 
> 
> Should we use the common.loader line or the shared.loader line ?

Leave them alone.  Don't touch either one.

> 
> 
> I would like to hear from the Tomcat experts so we can do it the right way.
> 

My suggestion would be to put JDBC drivers into "$CATALINA_BASE/lib" or "$CATALINA_HOME/lib" and put the rest of your JAR files in "WEB-INF/lib".  It's the simplest approach, it lets you easily hot redeploy your application and it cuts down on weird class loader issues.

Dan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org