You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Tobias Dittrich <to...@t-online.de> on 2002/12/23 09:59:08 UTC

Web app specific Listener (was Re: Listener Element in Context: class not found Exception)

Hi,

thanks for the answer, now I think I know where I got wrong. Listener
elements are tomcat server extensions rather than web app elements. But this
leads to my next question: how can I define web app sepcific listeners?
My goal is to have some application wide global jobs like reading
configuration etc. done when the application is brought up and do some
cleanup when it stops. And the object created by this process should be
accessable through the servlet context. I tried to find something like this
in the docs but so far I haven't been successfull - maybe anyone can give me
a hint under what topic to look?

Many thanks in advance
Tobi


----- Original Message -----
From: "Bill Barker" <wb...@wilshire.com>
To: <to...@jakarta.apache.org>
Sent: Saturday, December 21, 2002 7:58 AM
Subject: Re: Listener Element in Context: class not found Exception


>
> <to...@t-online.de> wrote in message
> news:1040385965.3e0307ad4859a@webmail.t-online.de...
> > Hello there,
> >
> > I have a problem with the <Listener> element inside a <Context> element
> >
> > in the server.xml configuration file. I always get a ClassNotFound
> > Exception for the class I specify in the attribute className when I
> > try to start catalina.
> >
> > I defined a Listener like this:
> >
> > <Host name="localhost" debug="1" appBase="webapps"
> >        unpackWARs="true" autoDeploy="true">
> >  [..]
> >   <Context path="/myapp" docBase="myapp" debug="1">
> >     <Listener className="com.mypackage.ListenerClass"/>
> >   </Context>
> >  [..]
> > </Host>
> >
> > The corresponding com.mypackage.ListenerClass resides inside it's web
> > application directory webapps/myapp/WEB-INF/classes. Now when I try to
>
> And that would be your problem ;-).  A Catalina Listener class can't be
> web-app specific.  You will need to move your class file to
> $CATALINA_HOME/server/classes.
>
> >
> > start the server I get a ClassNotFoundException for
> > com.mypackage.ListenerClass ...
> >
> > Now where do I have to put the classes so catalina can find them or is
> >
> > there a configuration file where I can point to this class? Supporting
> > a classpath doesn't help as catalina is setting it's own classpath.
> >
> > Any hints would be appreciated
> > Tobi


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Web app specific Listener (was Re: Listener Element in Context: class not found Exception)

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

On Mon, 23 Dec 2002, Tobias Dittrich wrote:

> Date: Mon, 23 Dec 2002 09:59:08 +0100
> From: Tobias Dittrich <to...@t-online.de>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: Web app specific Listener (was Re: Listener Element in Context:
>     class not found Exception)
>
> Hi,
>
> thanks for the answer, now I think I know where I got wrong. Listener
> elements are tomcat server extensions rather than web app elements. But this
> leads to my next question: how can I define web app sepcific listeners?
> My goal is to have some application wide global jobs like reading
> configuration etc. done when the application is brought up and do some
> cleanup when it stops. And the object created by this process should be
> accessable through the servlet context. I tried to find something like this
> in the docs but so far I haven't been successfull - maybe anyone can give me
> a hint under what topic to look?
>

Implement a javax.servlet.ServletContextListener in your webapp, and the
contextInitialized() method will be the place to do your startup
initialization stuff (including storing things in servlet context
attributes).  Likewise, the contextDestroyed() method can be used to clean
things up when the app is shut down.

Declare it in your web.xml file like this:

  <listener>
    <listener>com.mycompany.mypackage.MyListener</listener>
  </listener>

Because the order of elements in web.xml must match the order required by
the DTD, this element should go after any filters and before any
servlets.

> Many thanks in advance
> Tobi

Craig


>
>
> ----- Original Message -----
> From: "Bill Barker" <wb...@wilshire.com>
> To: <to...@jakarta.apache.org>
> Sent: Saturday, December 21, 2002 7:58 AM
> Subject: Re: Listener Element in Context: class not found Exception
>
>
> >
> > <to...@t-online.de> wrote in message
> > news:1040385965.3e0307ad4859a@webmail.t-online.de...
> > > Hello there,
> > >
> > > I have a problem with the <Listener> element inside a <Context> element
> > >
> > > in the server.xml configuration file. I always get a ClassNotFound
> > > Exception for the class I specify in the attribute className when I
> > > try to start catalina.
> > >
> > > I defined a Listener like this:
> > >
> > > <Host name="localhost" debug="1" appBase="webapps"
> > >        unpackWARs="true" autoDeploy="true">
> > >  [..]
> > >   <Context path="/myapp" docBase="myapp" debug="1">
> > >     <Listener className="com.mypackage.ListenerClass"/>
> > >   </Context>
> > >  [..]
> > > </Host>
> > >
> > > The corresponding com.mypackage.ListenerClass resides inside it's web
> > > application directory webapps/myapp/WEB-INF/classes. Now when I try to
> >
> > And that would be your problem ;-).  A Catalina Listener class can't be
> > web-app specific.  You will need to move your class file to
> > $CATALINA_HOME/server/classes.
> >
> > >
> > > start the server I get a ClassNotFoundException for
> > > com.mypackage.ListenerClass ...
> > >
> > > Now where do I have to put the classes so catalina can find them or is
> > >
> > > there a configuration file where I can point to this class? Supporting
> > > a classpath doesn't help as catalina is setting it's own classpath.
> > >
> > > Any hints would be appreciated
> > > Tobi
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>