You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mark Benussi <ma...@hotmail.com> on 2005/07/27 11:55:24 UTC

Placing a LifecycleListener in my server.xml

Anyone have any ideas where on earth I put my class that implements the
LifecycleListener (In a jar in my WEB-INF/lib) as I don't seem to have a
context in my server.xml.

<Server port="8005" shutdown="SHUTDOWN" debug="0">
	<Listener
className="org.apache.catalina.mbeans.ServerLifecycleListener" debug="0"/>
	<Listener
className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
debug="0"/>
	<GlobalNamingResources>
		<Environment name="simpleValue" type="java.lang.Integer"
value="30"/>
		<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase" description="User database that can
be updated and saved">
    </Resource>
		<ResourceParams name="UserDatabase">
			<parameter>
				<name>factory</name>
	
<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
			</parameter>
			<parameter>
				<name>pathname</name>
				<value>conf/tomcat-users.xml</value>
			</parameter>
		</ResourceParams>
	</GlobalNamingResources>
	<Service name="Catalina">
		<Connector port="80" maxThreads="150" minSpareThreads="25"
maxSpareThreads="75" enableLookups="false" redirectPort="443"
acceptCount="100" debug="0" connectionTimeout="20000"
disableUploadTimeout="true"/>
		<Connector port="443" maxThreads="150" minSpareThreads="25"
maxSpareThreads="75" enableLookups="false" disableUploadTimeout="true"
acceptCount="100" debug="0" scheme="https" secure="true" clientAuth="false"
sslProtocol="TLS"/>
		<Connector port="8009" enableLookups="false"
redirectPort="443" debug="0" protocol="AJP/1.3"/>
		<Engine name="Catalina" defaultHost="localhost" debug="0">
			<Logger
className="org.apache.catalina.logger.FileLogger" prefix="catalina_log."
suffix=".txt" timestamp="true"/>
			<Realm
className="org.apache.catalina.realm.UserDatabaseRealm" debug="0"
resourceName="UserDatabase"/>
			<Host name="localhost" debug="0" appBase="webapps"
unpackWARs="true" autoDeploy="true" xmlValidation="false"
xmlNamespaceAware="false">
				<Logger
className="org.apache.catalina.logger.FileLogger" directory="logs"
prefix="localhost_log." suffix=".txt" timestamp="true"/>
			</Host>
		</Engine>
	</Service>
</Server>



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


Re: Placing a LifecycleListener in my server.xml

Posted by "Darryl L. Miles" <da...@netbauds.net>.
Mark Benussi wrote:

>Thanks Darryl
>
>I have followed this guide but don't know how to add the modify the
>server.xml I attached to reflect this. Also are you saying I should put the
>class that implements the listener in the server/classes?
>
>I am fine with this but wasn't sure if it would all get loaded together as
>the class is a Singleton that the rest of my code talks to and need to be
>sure it will have access to the same class instance in the JVM.
>
>  
>
 From the example you quoted right at the top there is:

[...SNIP...]
<Server port="8005" shutdown="SHUTDOWN" debug="0">
	<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" debug="0"/>
	<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" debug="0"/>
	<GlobalNamingResources>
[...SNIP...]

So you just add your:
   <Listener className="my.domain.class.LifecycleListener"/>


To confirm location grep "jar -tvf tomcat-foobar.jar" from 
$CATALINA_HOME/servers/lib for mbeans/ServerLifecycleListener.class.

As for ensuring the SAME instance of the Singleton is found, maybe you 
must put it into $CATALINA_HOME/common/lib not server/lib!  Please read 
up on the differencies for clarification.

It is my understanding that only the Tomcat Application Server itself 
loads classes from $CATALINA_HOME/servers/* and that all librarys in 
$CATALINA_HOME/common/* are available to both the AS and the WEBAPP 
contexts.  Just make sure you dont override the class by also installing 
it into the WEB-INF/* area.

If this does not work maybe JNDI is the only way, that is bind the 
instance to a JNDI path at the first lifecycle event then all the 
webapps can lookup and use it  (if simplistic class loading does not work).

I have not used this method before as I found other ways to do what I 
needed, I wanted to deploy the listener within my webapp.


>-----Original Message-----
>From: Darryl L. Miles [mailto:darryl@netbauds.net] 
>Sent: 27 July 2005 12:10
>To: Tomcat Users List
>Subject: Re: Placing a LifecycleListener in my server.xml
>
>
>Sorry did not read properly..
>
>Have you tried:
>
>for JARs:  $CATALINA_HOME/server/lib or $CATALINA_HOME/common/lib
>for .class: $CATALINA_HOME/server/classes or $CATALINA_HOME/common/classes
>
>
>From: http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/context.html
>
>*Lifecycle Listeners*
>
>    If you have implemented a Java object that needs to know when this
>    *Context* is started or stopped, you can declare it by nesting a
>    *Listener* element inside this element. The class name you specify
>    must implement the |org.apache.catalina.LifecycleListener|
>    interface, and it will be notified about the occurrence of the
>    coresponding lifecycle events. Configuration of such a listener
>    looks like this:
>
><Context path="/examples" ...>
>  ...
>  <Listener className="com.mycompany.mypackage.MyListener" ... >
>  ...
></Context>
>	
>    Note that a Listener can have any number of additional properties
>    that may be configured from this element. Attribute names are
>    matched to corresponding JavaBean property names using the standard
>    property method naming patterns.
>
>  
>

-- 
Darryl L. Miles



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


RE: Placing a LifecycleListener in my server.xml

Posted by Mark Benussi <ma...@hotmail.com>.
Thanks Darryl

I have followed this guide but don't know how to add the modify the
server.xml I attached to reflect this. Also are you saying I should put the
class that implements the listener in the server/classes?

I am fine with this but wasn't sure if it would all get loaded together as
the class is a Singleton that the rest of my code talks to and need to be
sure it will have access to the same class instance in the JVM.

-----Original Message-----
From: Darryl L. Miles [mailto:darryl@netbauds.net] 
Sent: 27 July 2005 12:10
To: Tomcat Users List
Subject: Re: Placing a LifecycleListener in my server.xml


Sorry did not read properly..

Have you tried:

for JARs:  $CATALINA_HOME/server/lib or $CATALINA_HOME/common/lib
for .class: $CATALINA_HOME/server/classes or $CATALINA_HOME/common/classes


From: http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/context.html

*Lifecycle Listeners*

    If you have implemented a Java object that needs to know when this
    *Context* is started or stopped, you can declare it by nesting a
    *Listener* element inside this element. The class name you specify
    must implement the |org.apache.catalina.LifecycleListener|
    interface, and it will be notified about the occurrence of the
    coresponding lifecycle events. Configuration of such a listener
    looks like this:

    		
    	

<Context path="/examples" ...>
  ...
  <Listener className="com.mycompany.mypackage.MyListener" ... >
  ...
</Context>
        

    	
    		

    Note that a Listener can have any number of additional properties
    that may be configured from this element. Attribute names are
    matched to corresponding JavaBean property names using the standard
    property method naming patterns.






Mark Benussi wrote:

> Thanks Darryl but I need to implement a LifecycleListener. You have 
> implemented a ServletContextListener which only gets called when the 
> Content is started. I need to know when its finished, which is why I 
> am using a LifecycleListener which should be placed in the server.xml
>
> ----Original Message Follows----
> From: "Darryl L. Miles" <da...@netbauds.net>
> Reply-To: "Tomcat Users List" <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: Re: Placing a LifecycleListener in my server.xml
> Date: Wed, 27 Jul 2005 11:47:17 +0100
>
> Mark Benussi wrote:
>
>> Anyone have any ideas where on earth I put my class that implements the
>> LifecycleListener (In a jar in my WEB-INF/lib) as I don't seem to have a
>> context in my server.xml.
>>
>>
> The context is in WEB-INF/web.xml
>
> as its a webapp specific listener, NOT a global server thing.
>
> See my article http://www.hibernate.org/301.html as an example (when 
> used with hibernate)
>
> -- 
> Darryl L. Miles
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
> .
>


-- 
Darryl L. Miles
M: 07968 320 114


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


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


Re: Placing a LifecycleListener in my server.xml

Posted by "Darryl L. Miles" <da...@netbauds.net>.
Sorry did not read properly..

Have you tried:

for JARs:  $CATALINA_HOME/server/lib or $CATALINA_HOME/common/lib
for .class: $CATALINA_HOME/server/classes or $CATALINA_HOME/common/classes


From: http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/context.html

*Lifecycle Listeners*

    If you have implemented a Java object that needs to know when this
    *Context* is started or stopped, you can declare it by nesting a
    *Listener* element inside this element. The class name you specify
    must implement the |org.apache.catalina.LifecycleListener|
    interface, and it will be notified about the occurrence of the
    coresponding lifecycle events. Configuration of such a listener
    looks like this:

    		
    	

<Context path="/examples" ...>
  ...
  <Listener className="com.mycompany.mypackage.MyListener" ... >
  ...
</Context>
        

    	
    		

    Note that a Listener can have any number of additional properties
    that may be configured from this element. Attribute names are
    matched to corresponding JavaBean property names using the standard
    property method naming patterns.






Mark Benussi wrote:

> Thanks Darryl but I need to implement a LifecycleListener. You have 
> implemented a ServletContextListener which only gets called when the 
> Content is started. I need to know when its finished, which is why I 
> am using a LifecycleListener which should be placed in the server.xml
>
> ----Original Message Follows----
> From: "Darryl L. Miles" <da...@netbauds.net>
> Reply-To: "Tomcat Users List" <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: Re: Placing a LifecycleListener in my server.xml
> Date: Wed, 27 Jul 2005 11:47:17 +0100
>
> Mark Benussi wrote:
>
>> Anyone have any ideas where on earth I put my class that implements the
>> LifecycleListener (In a jar in my WEB-INF/lib) as I don't seem to have a
>> context in my server.xml.
>>
>>
> The context is in WEB-INF/web.xml
>
> as its a webapp specific listener, NOT a global server thing.
>
> See my article http://www.hibernate.org/301.html as an example (when 
> used with hibernate)
>
> -- 
> Darryl L. Miles
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
> .
>


-- 
Darryl L. Miles
M: 07968 320 114


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


Re: Placing a LifecycleListener in my server.xml

Posted by "Darryl L. Miles" <da...@netbauds.net>.
Sorry did not read properly..

Have you tried:

for JARs:  $CATALINA_HOME/server/lib or $CATALINA_HOME/common/lib
for .class: $CATALINA_HOME/server/classes or $CATALINA_HOME/common/classes


From: http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/context.html

*Lifecycle Listeners*

    If you have implemented a Java object that needs to know when this
    *Context* is started or stopped, you can declare it by nesting a
    *Listener* element inside this element. The class name you specify
    must implement the |org.apache.catalina.LifecycleListener|
    interface, and it will be notified about the occurrence of the
    coresponding lifecycle events. Configuration of such a listener
    looks like this:

    		
    	

<Context path="/examples" ...>
  ...
  <Listener className="com.mycompany.mypackage.MyListener" ... >
  ...
</Context>
        

    	
    		

    Note that a Listener can have any number of additional properties
    that may be configured from this element. Attribute names are
    matched to corresponding JavaBean property names using the standard
    property method naming patterns.






Mark Benussi wrote:

> Thanks Darryl but I need to implement a LifecycleListener. You have 
> implemented a ServletContextListener which only gets called when the 
> Content is started. I need to know when its finished, which is why I 
> am using a LifecycleListener which should be placed in the server.xml
>
> ----Original Message Follows----
> From: "Darryl L. Miles" <da...@netbauds.net>
> Reply-To: "Tomcat Users List" <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: Re: Placing a LifecycleListener in my server.xml
> Date: Wed, 27 Jul 2005 11:47:17 +0100
>
> Mark Benussi wrote:
>
>> Anyone have any ideas where on earth I put my class that implements the
>> LifecycleListener (In a jar in my WEB-INF/lib) as I don't seem to have a
>> context in my server.xml.
>>
>>
> The context is in WEB-INF/web.xml
>
> as its a webapp specific listener, NOT a global server thing.
>
> See my article http://www.hibernate.org/301.html as an example (when 
> used with hibernate)
>
> -- 
> Darryl L. Miles
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
> .
>


-- 
Darryl L. Miles



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


Re: Placing a LifecycleListener in my server.xml

Posted by Mark Benussi <ma...@hotmail.com>.
Thanks Darryl but I need to implement a LifecycleListener. You have 
implemented a ServletContextListener which only gets called when the Content 
is started. I need to know when its finished, which is why I am using a 
LifecycleListener which should be placed in the server.xml

----Original Message Follows----
From: "Darryl L. Miles" <da...@netbauds.net>
Reply-To: "Tomcat Users List" <to...@jakarta.apache.org>
To: Tomcat Users List <to...@jakarta.apache.org>
Subject: Re: Placing a LifecycleListener in my server.xml
Date: Wed, 27 Jul 2005 11:47:17 +0100

Mark Benussi wrote:

>Anyone have any ideas where on earth I put my class that implements the
>LifecycleListener (In a jar in my WEB-INF/lib) as I don't seem to have a
>context in my server.xml.
>
>
The context is in WEB-INF/web.xml

as its a webapp specific listener, NOT a global server thing.

See my article http://www.hibernate.org/301.html as an example (when used 
with hibernate)

--
Darryl L. Miles



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



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


Re: Placing a LifecycleListener in my server.xml

Posted by "Darryl L. Miles" <da...@netbauds.net>.
Mark Benussi wrote:

>Anyone have any ideas where on earth I put my class that implements the
>LifecycleListener (In a jar in my WEB-INF/lib) as I don't seem to have a
>context in my server.xml.
>  
>
The context is in WEB-INF/web.xml

as its a webapp specific listener, NOT a global server thing.

See my article http://www.hibernate.org/301.html as an example (when 
used with hibernate)

-- 
Darryl L. Miles



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