You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by James Turner <tu...@blackbear.com> on 2001/10/02 23:52:59 UTC

Where to put ServletContextListener?

I'm trying to use a ServletContextListener to initialize Turbine
standalone for my application.  Here's the class:

package com.bfg.services;
import org.apache.turbine.util.TurbineConfig;

public class BfgListener implements javax.servlet.ServletContextListener
{
    public void contextDestroyed(javax.servlet.ServletContextEvent sce)
{
    }

    public void contextInitialized(javax.servlet.ServletContextEvent
sce) {
	TurbineConfig tc = new
TurbineConfig("/","TurbineResources.properties");
	tc.init();
	
    }
}

Here's the server.xml excerpt:
        <Context path="/bfg" docBase="bfg" debug="0"
                 reloadable="true">
	  <Listener className="com.bfg.services.BfgListener">

I've tried putting the class in the jar with the rest of the bfg
classes, in a jar in the tomcat lib directory, in the tomcat classes
directory, in the webapp lib and classes directory, and I still get the
same error on startup:

Catalina.start: java.lang.ClassNotFoundException:
com.bfg.services.BfgListener
java.lang.ClassNotFoundException: com.bfg.services.BfgListener

Where does it need to live?  I've seen the question asked on this list,
but not the answer.

James


RE: Where to put ServletContextListener?

Posted by James Turner <tu...@blackbear.com>.
Thanks for the info, Sir.

James

> -----Original Message-----
> From: craigmcc@h00608cebfd77.ne.mediaone.net 
> [mailto:craigmcc@h00608cebfd77.ne.mediaone.net] On Behalf Of 
> Craig R. McClanahan
> Sent: Tuesday, October 02, 2001 7:15 PM
> To: tomcat-user@jakarta.apache.org
> Subject: Re: Where to put ServletContextListener?
> 
> 
> 
> 
> On Tue, 2 Oct 2001, James Turner wrote:
> 
> > Date: Tue, 2 Oct 2001 17:52:59 -0400
> > From: James Turner <tu...@blackbear.com>
> > Reply-To: tomcat-user@jakarta.apache.org
> > To: tomcat-user@jakarta.apache.org
> > Subject: Where to put ServletContextListener?
> >
> > I'm trying to use a ServletContextListener to initialize Turbine 
> > standalone for my application.  Here's the class:
> >
> > package com.bfg.services;
> > import org.apache.turbine.util.TurbineConfig;
> >
> > public class BfgListener implements 
> > javax.servlet.ServletContextListener
> > {
> >     public void 
> contextDestroyed(javax.servlet.ServletContextEvent sce)
> > {
> >     }
> >
> >     public void contextInitialized(javax.servlet.ServletContextEvent
> > sce) {
> > 	TurbineConfig tc = new 
> > TurbineConfig("/","TurbineResources.properties");
> > 	tc.init();
> >
> >     }
> > }
> >
> 
> Because ServletContextListener is a standard part of the 
> Servlet API, your corresponding class goes inside your webapp 
> (in /WEB-INF/classes or /WEB-INF/lib), just like servlets and 
> bean classes do.
> 
> You declare your listener in the /WEB-INF/web.xml file, like this:
> 
>   <listener>
>     <listener-class>com.bfg.services.BfgListener</listener-class>
>   </listener>
> 
> The "examples" web app that comes with Tomcat 4 declares 
> several listeners in exactly this way -- take a look at the 
> web.xml file there to get the idea.
> 
> > Here's the server.xml excerpt:
> >         <Context path="/bfg" docBase="bfg" debug="0"
> >                  reloadable="true">
> > 	  <Listener className="com.bfg.services.BfgListener">
> >
> > I've tried putting the class in the jar with the rest of the bfg 
> > classes, in a jar in the tomcat lib directory, in the 
> tomcat classes 
> > directory, in the webapp lib and classes directory, and I still get 
> > the same error on startup:
> >
> > Catalina.start: java.lang.ClassNotFoundException: 
> > com.bfg.services.BfgListener
> > java.lang.ClassNotFoundException: com.bfg.services.BfgListener
> >
> 
> This is for internal-to-Tomcat listeners that operate 
> "inside" the container, rather than as part of your 
> application.  You don't need to worry about this at all.
> 
> > Where does it need to live?  I've seen the question asked on this 
> > list, but not the answer.
> >
> 
> Listeners (and Filters, if you use them) go in your web app, 
> just like other application classes, and they are configured 
> in /WEB-INF/web.xml.
> 
> > James
> >
> >
> 
> Craig McClanahan
> 
> 
> 


Re: Where to put ServletContextListener?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 2 Oct 2001, James Turner wrote:

> Date: Tue, 2 Oct 2001 17:52:59 -0400
> From: James Turner <tu...@blackbear.com>
> Reply-To: tomcat-user@jakarta.apache.org
> To: tomcat-user@jakarta.apache.org
> Subject: Where to put ServletContextListener?
>
> I'm trying to use a ServletContextListener to initialize Turbine
> standalone for my application.  Here's the class:
>
> package com.bfg.services;
> import org.apache.turbine.util.TurbineConfig;
>
> public class BfgListener implements javax.servlet.ServletContextListener
> {
>     public void contextDestroyed(javax.servlet.ServletContextEvent sce)
> {
>     }
>
>     public void contextInitialized(javax.servlet.ServletContextEvent
> sce) {
> 	TurbineConfig tc = new
> TurbineConfig("/","TurbineResources.properties");
> 	tc.init();
>
>     }
> }
>

Because ServletContextListener is a standard part of the Servlet API, your
corresponding class goes inside your webapp (in /WEB-INF/classes or
/WEB-INF/lib), just like servlets and bean classes do.

You declare your listener in the /WEB-INF/web.xml file, like this:

  <listener>
    <listener-class>com.bfg.services.BfgListener</listener-class>
  </listener>

The "examples" web app that comes with Tomcat 4 declares several listeners
in exactly this way -- take a look at the web.xml file there to get the
idea.

> Here's the server.xml excerpt:
>         <Context path="/bfg" docBase="bfg" debug="0"
>                  reloadable="true">
> 	  <Listener className="com.bfg.services.BfgListener">
>
> I've tried putting the class in the jar with the rest of the bfg
> classes, in a jar in the tomcat lib directory, in the tomcat classes
> directory, in the webapp lib and classes directory, and I still get the
> same error on startup:
>
> Catalina.start: java.lang.ClassNotFoundException:
> com.bfg.services.BfgListener
> java.lang.ClassNotFoundException: com.bfg.services.BfgListener
>

This is for internal-to-Tomcat listeners that operate "inside" the
container, rather than as part of your application.  You don't need to
worry about this at all.

> Where does it need to live?  I've seen the question asked on this list,
> but not the answer.
>

Listeners (and Filters, if you use them) go in your web app, just like
other application classes, and they are configured in /WEB-INF/web.xml.

> James
>
>

Craig McClanahan