You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Juanjo Cuadrado <jj...@gmail.com> on 2006/05/15 23:08:02 UTC

Run class in the start up of Tomcat

Hi,

   I'm trying to run a class in startup of Tomcat. I think that this was
possible in others versions of Tomcat (I just started with Tomcat 5). I
think that it was a property in someone element of server.xml that allowed
this.

    Anyone can help me? I hope that yes ;) tx

Re: Run class in the start up of Tomcat

Posted by Mark Thomas <ma...@apache.org>.
Asaf Lahav wrote:
> Is it possible to stop the tomcat shutdown sequence from with in the context
> listener contextDestroyed function?

No. The shutdown process has already started for the application and a
number of other components have already been stopped.

Mark

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


RE: Run class in the start up of Tomcat

Posted by Asaf Lahav <as...@primagrid.com>.
Is it possible to stop the tomcat shutdown sequence from with in the context
listener contextDestroyed function?

 

Asaf Lahav

 

VP R&D, Prima Grid LTD.

 

Cellular:  972-54-4717955

 

Phone:   972-3-6540255

 

Fax:       972-3-6540254

 

 

 

 

-----Original Message-----
From: Asaf Lahav [mailto:asaf.lahav@primagrid.com] 
Sent: Monday, May 29, 2006 1:24 PM
To: 'Tomcat Users List'
Subject: RE: Run class in the start up of Tomcat

 

Thanks Juanjo,

That link helped.

 

Asaf Lahav

 

VP R&D, Prima Grid LTD.

 

Cellular:  972-54-4717955

 

Phone:   972-3-6540255

 

Fax:       972-3-6540254

 

 

 

-----Original Message-----

From: Juanjo Cuadrado [mailto:jjcuadrado@gmail.com] 

Sent: Monday, May 29, 2006 10:23 AM

To: Tomcat Users List

Subject: Re: Run class in the start up of Tomcat

 

Hi,

 

    I don't know if i'm understanding well, but my English is very bad...

sorry.

 

    I used, like you, the ServletContextListener. I only used two methods,

contextInitialized and contextDestroyed, to monitor when Tomcat start or

stop, buy there are two more to monitor the start and stop sessions. In this

URL you can see a example.

 

 

http://www.stardeveloper.com/articles/display.html?article=2001111901&page=1

 

    I hope help you.

 

 

 

 

 

2006/5/28, Asaf Lahav <as...@primagrid.com>:

> 

> Wouldn't it be better to develop a ServletContextListener servlet?

> 

> 

> 

> Anyhow,

> 

> I did give it a try and I attempt to develop a ServletContextListener

> servlet.

> 

> This is the code I'm using (took it from tomcat servlet samples):

> 

> /**

> 

> *

> 

> */

> 

> package starters;

> 

> 

> 

> import javax.servlet.ServletContext;

> 

> import javax.servlet.ServletContextAttributeEvent;

> 

> import javax.servlet.ServletContextAttributeListener;

> 

> import javax.servlet.ServletContextEvent;

> 

> import javax.servlet.ServletContextListener;

> 

> 

> 

> public class ContextServletsTest implements

> ServletContextAttributeListener,

> 

>             ServletContextListener {

> 

> 

> 

>        /**

> 

>      * The servlet context with which we are associated.

> 

>      */

> 

>     private ServletContext context = null;

> 

> 

> 

> 

> 

>     // --------------------------------------------------------- Public

> Methods

> 

> 

> 

> 

> 

>     /**

> 

>      * Record the fact that a servlet context attribute was added.

> 

>      *

> 

>      * @param event The servlet context attribute event

> 

>      */

> 

>     public void attributeAdded(ServletContextAttributeEvent event) {

> 

> 

> 

>       log("attributeAdded('" + event.getName() + "', '" +

> 

>           event.getValue() + "')");

> 

> 

> 

>     }

> 

> 

> 

> 

> 

>     /**

> 

>      * Record the fact that a servlet context attribute was removed.

> 

>      *

> 

>      * @param event The servlet context attribute event

> 

>      */

> 

>     public void attributeRemoved(ServletContextAttributeEvent event) {

> 

> 

> 

>       log("attributeRemoved('" + event.getName() + "', '" +

> 

>           event.getValue() + "')");

> 

> 

> 

>     }

> 

> 

> 

> 

> 

>     /**

> 

>      * Record the fact that a servlet context attribute was replaced.

> 

>      *

> 

>      * @param event The servlet context attribute event

> 

>      */

> 

>     public void attributeReplaced(ServletContextAttributeEvent event) {

> 

> 

> 

>       log("attributeReplaced('" + event.getName() + "', '" +

> 

>           event.getValue() + "')");

> 

> 

> 

>     }

> 

> 

> 

> 

> 

>     /**

> 

>      * Record the fact that this web application has been destroyed.

> 

>      *

> 

>      * @param event The servlet context event

> 

>      */

> 

>     public void contextDestroyed(ServletContextEvent event) {

> 

> 

> 

>       log("contextDestroyed()");

> 

>       this.context = null;

> 

> 

> 

>     }

> 

> 

> 

> 

> 

>     /**

> 

>      * Record the fact that this web application has been initialized.

> 

>      *

> 

>      * @param event The servlet context event

> 

>      */

> 

>     public void contextInitialized(ServletContextEvent event) {

> 

> 

> 

>       this.context = event.getServletContext();

> 

>       log("contextInitialized()");

> 

> 

> 

>     }

> 

> 

> 

> 

> 

>     // -------------------------------------------------------- Private

> Methods

> 

> 

> 

> 

> 

>     /**

> 

>      * Log a message to the servlet context application log.

> 

>      *

> 

>      * @param message Message to be logged

> 

>      */

> 

>     private void log(String message) {

> 

> 

> 

>       if (context != null)

> 

>           context.log("ContextListener: " + message);

> 

>       else

> 

>           System.out.println("ContextListener: " + message);

> 

> 

> 

>     }

> 

> 

> 

> 

> 

>     /**

> 

>      * Log a message and associated exception to the servlet context

> 

>      * application log.

> 

>      *

> 

>      * @param message Message to be logged

> 

>      * @param throwable Exception to be logged

> 

>      */

> 

>     private void log(String message, Throwable throwable) {

> 

> 

> 

>             if (context != null)

> 

>                 context.log("ContextListener: " + message, throwable);

> 

>             else {

> 

>                 System.out.println("ContextListener: " + message);

> 

>                 throwable.printStackTrace(System.out);

> 

>             }

> 

> 

> 

>     }

> 

> 

> 

> }

> 

> 

> 

> I also added a Listener entry in the application web.xml:

> 

>             <listener>

> 

> 

> <listener-class>starters.ContextServletsTest</listener-class>

> 

>       </listener>

> 

> 

> 

> For some reason its not working and I can't figure it out.

> 

> Apperently I did every thing as required. Yet it doesn't function at all.

> 

> Thanks in advance,

> 

> 

> 

> Asaf Lahav

> 

> 

> 

> VP R&D, Prima Grid LTD.

> 

> 

> 

> Cellular:  972-54-4717955

> 

> 

> 

> Phone:   972-3-6540255

> 

> 

> 

> Fax:       972-3-6540254

> 

> 

> 

> 

> 

> 

> 

> -----Original Message-----

> From: Parsons Technical Services [mailto:parsonstechnical@earthlink.net]

> Sent: Monday, May 15, 2006 11:45 PM

> To: Tomcat Users List

> Subject: Re: Run class in the start up of Tomcat

> 

> 

> 

> Are you wanting to start a servlet or load a class?

> 

> 

> 

> You can load a servlet at the application level.

> 

> load-on-startup in the servlet class element in the web.xml of the app.

> 

> 

> 

>   <servlet>

> 

>      <servlet-name>Scored</servlet-name>

> 

>      <servlet-class>srm.Scored</servlet-class>

> 

>      <load-on-startup>1</load-on-startup>

> 

>     </servlet>

> 

> 

> 

> The number indicates the order that the servlet is loaded.

> 

> 

> 

> As for a class you will need to look into the class loader for Tomcat.

> 

> 

> 

> http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html

> 

> 

> 

> Doug

> 

> 

> 

> 

> 

> ----- Original Message -----

> 

> From: "Juanjo Cuadrado" <jj...@gmail.com>

> 

> To: <us...@tomcat.apache.org>

> 

> Sent: Monday, May 15, 2006 5:08 PM

> 

> Subject: Run class in the start up of Tomcat

> 

> 

> 

> 

> 

> Hi,

> 

> 

> 

>    I'm trying to run a class in startup of Tomcat. I think that this was

> 

> possible in others versions of Tomcat (I just started with Tomcat 5). I

> 

> think that it was a property in someone element of server.xml that allowed

> 

> this.

> 

> 

> 

>     Anyone can help me? I hope that yes ;) tx

> 

> 

> 

> 

> 

> 

> 

> ---------------------------------------------------------------------

> 

> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org

> 

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

> 

> 

> 

 

 

---------------------------------------------------------------------

To start a new topic, e-mail: users@tomcat.apache.org

To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org

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


RE: Run class in the start up of Tomcat

Posted by Asaf Lahav <as...@primagrid.com>.
Thanks Juanjo,
That link helped.

Asaf Lahav

VP R&D, Prima Grid LTD.

Cellular:  972-54-4717955

Phone:   972-3-6540255

Fax:       972-3-6540254

 

-----Original Message-----
From: Juanjo Cuadrado [mailto:jjcuadrado@gmail.com] 
Sent: Monday, May 29, 2006 10:23 AM
To: Tomcat Users List
Subject: Re: Run class in the start up of Tomcat

Hi,

    I don't know if i'm understanding well, but my English is very bad...
sorry.

    I used, like you, the ServletContextListener. I only used two methods,
contextInitialized and contextDestroyed, to monitor when Tomcat start or
stop, buy there are two more to monitor the start and stop sessions. In this
URL you can see a example.


http://www.stardeveloper.com/articles/display.html?article=2001111901&page=1

    I hope help you.





2006/5/28, Asaf Lahav <as...@primagrid.com>:
>
> Wouldn't it be better to develop a ServletContextListener servlet?
>
>
>
> Anyhow,
>
> I did give it a try and I attempt to develop a ServletContextListener
> servlet.
>
> This is the code I'm using (took it from tomcat servlet samples):
>
> /**
>
> *
>
> */
>
> package starters;
>
>
>
> import javax.servlet.ServletContext;
>
> import javax.servlet.ServletContextAttributeEvent;
>
> import javax.servlet.ServletContextAttributeListener;
>
> import javax.servlet.ServletContextEvent;
>
> import javax.servlet.ServletContextListener;
>
>
>
> public class ContextServletsTest implements
> ServletContextAttributeListener,
>
>             ServletContextListener {
>
>
>
>        /**
>
>      * The servlet context with which we are associated.
>
>      */
>
>     private ServletContext context = null;
>
>
>
>
>
>     // --------------------------------------------------------- Public
> Methods
>
>
>
>
>
>     /**
>
>      * Record the fact that a servlet context attribute was added.
>
>      *
>
>      * @param event The servlet context attribute event
>
>      */
>
>     public void attributeAdded(ServletContextAttributeEvent event) {
>
>
>
>       log("attributeAdded('" + event.getName() + "', '" +
>
>           event.getValue() + "')");
>
>
>
>     }
>
>
>
>
>
>     /**
>
>      * Record the fact that a servlet context attribute was removed.
>
>      *
>
>      * @param event The servlet context attribute event
>
>      */
>
>     public void attributeRemoved(ServletContextAttributeEvent event) {
>
>
>
>       log("attributeRemoved('" + event.getName() + "', '" +
>
>           event.getValue() + "')");
>
>
>
>     }
>
>
>
>
>
>     /**
>
>      * Record the fact that a servlet context attribute was replaced.
>
>      *
>
>      * @param event The servlet context attribute event
>
>      */
>
>     public void attributeReplaced(ServletContextAttributeEvent event) {
>
>
>
>       log("attributeReplaced('" + event.getName() + "', '" +
>
>           event.getValue() + "')");
>
>
>
>     }
>
>
>
>
>
>     /**
>
>      * Record the fact that this web application has been destroyed.
>
>      *
>
>      * @param event The servlet context event
>
>      */
>
>     public void contextDestroyed(ServletContextEvent event) {
>
>
>
>       log("contextDestroyed()");
>
>       this.context = null;
>
>
>
>     }
>
>
>
>
>
>     /**
>
>      * Record the fact that this web application has been initialized.
>
>      *
>
>      * @param event The servlet context event
>
>      */
>
>     public void contextInitialized(ServletContextEvent event) {
>
>
>
>       this.context = event.getServletContext();
>
>       log("contextInitialized()");
>
>
>
>     }
>
>
>
>
>
>     // -------------------------------------------------------- Private
> Methods
>
>
>
>
>
>     /**
>
>      * Log a message to the servlet context application log.
>
>      *
>
>      * @param message Message to be logged
>
>      */
>
>     private void log(String message) {
>
>
>
>       if (context != null)
>
>           context.log("ContextListener: " + message);
>
>       else
>
>           System.out.println("ContextListener: " + message);
>
>
>
>     }
>
>
>
>
>
>     /**
>
>      * Log a message and associated exception to the servlet context
>
>      * application log.
>
>      *
>
>      * @param message Message to be logged
>
>      * @param throwable Exception to be logged
>
>      */
>
>     private void log(String message, Throwable throwable) {
>
>
>
>             if (context != null)
>
>                 context.log("ContextListener: " + message, throwable);
>
>             else {
>
>                 System.out.println("ContextListener: " + message);
>
>                 throwable.printStackTrace(System.out);
>
>             }
>
>
>
>     }
>
>
>
> }
>
>
>
> I also added a Listener entry in the application web.xml:
>
>             <listener>
>
>
> <listener-class>starters.ContextServletsTest</listener-class>
>
>       </listener>
>
>
>
> For some reason its not working and I can't figure it out.
>
> Apperently I did every thing as required. Yet it doesn't function at all.
>
> Thanks in advance,
>
>
>
> Asaf Lahav
>
>
>
> VP R&D, Prima Grid LTD.
>
>
>
> Cellular:  972-54-4717955
>
>
>
> Phone:   972-3-6540255
>
>
>
> Fax:       972-3-6540254
>
>
>
>
>
>
>
> -----Original Message-----
> From: Parsons Technical Services [mailto:parsonstechnical@earthlink.net]
> Sent: Monday, May 15, 2006 11:45 PM
> To: Tomcat Users List
> Subject: Re: Run class in the start up of Tomcat
>
>
>
> Are you wanting to start a servlet or load a class?
>
>
>
> You can load a servlet at the application level.
>
> load-on-startup in the servlet class element in the web.xml of the app.
>
>
>
>   <servlet>
>
>      <servlet-name>Scored</servlet-name>
>
>      <servlet-class>srm.Scored</servlet-class>
>
>      <load-on-startup>1</load-on-startup>
>
>     </servlet>
>
>
>
> The number indicates the order that the servlet is loaded.
>
>
>
> As for a class you will need to look into the class loader for Tomcat.
>
>
>
> http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html
>
>
>
> Doug
>
>
>
>
>
> ----- Original Message -----
>
> From: "Juanjo Cuadrado" <jj...@gmail.com>
>
> To: <us...@tomcat.apache.org>
>
> Sent: Monday, May 15, 2006 5:08 PM
>
> Subject: Run class in the start up of Tomcat
>
>
>
>
>
> Hi,
>
>
>
>    I'm trying to run a class in startup of Tomcat. I think that this was
>
> possible in others versions of Tomcat (I just started with Tomcat 5). I
>
> think that it was a property in someone element of server.xml that allowed
>
> this.
>
>
>
>     Anyone can help me? I hope that yes ;) tx
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
>
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>


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


Re: Run class in the start up of Tomcat

Posted by Juanjo Cuadrado <jj...@gmail.com>.
Hi,

    I don't know if i'm understanding well, but my English is very bad...
sorry.

    I used, like you, the ServletContextListener. I only used two methods,
contextInitialized and contextDestroyed, to monitor when Tomcat start or
stop, buy there are two more to monitor the start and stop sessions. In this
URL you can see a example.


http://www.stardeveloper.com/articles/display.html?article=2001111901&page=1

    I hope help you.





2006/5/28, Asaf Lahav <as...@primagrid.com>:
>
> Wouldn't it be better to develop a ServletContextListener servlet?
>
>
>
> Anyhow,
>
> I did give it a try and I attempt to develop a ServletContextListener
> servlet.
>
> This is the code I'm using (took it from tomcat servlet samples):
>
> /**
>
> *
>
> */
>
> package starters;
>
>
>
> import javax.servlet.ServletContext;
>
> import javax.servlet.ServletContextAttributeEvent;
>
> import javax.servlet.ServletContextAttributeListener;
>
> import javax.servlet.ServletContextEvent;
>
> import javax.servlet.ServletContextListener;
>
>
>
> public class ContextServletsTest implements
> ServletContextAttributeListener,
>
>             ServletContextListener {
>
>
>
>        /**
>
>      * The servlet context with which we are associated.
>
>      */
>
>     private ServletContext context = null;
>
>
>
>
>
>     // --------------------------------------------------------- Public
> Methods
>
>
>
>
>
>     /**
>
>      * Record the fact that a servlet context attribute was added.
>
>      *
>
>      * @param event The servlet context attribute event
>
>      */
>
>     public void attributeAdded(ServletContextAttributeEvent event) {
>
>
>
>       log("attributeAdded('" + event.getName() + "', '" +
>
>           event.getValue() + "')");
>
>
>
>     }
>
>
>
>
>
>     /**
>
>      * Record the fact that a servlet context attribute was removed.
>
>      *
>
>      * @param event The servlet context attribute event
>
>      */
>
>     public void attributeRemoved(ServletContextAttributeEvent event) {
>
>
>
>       log("attributeRemoved('" + event.getName() + "', '" +
>
>           event.getValue() + "')");
>
>
>
>     }
>
>
>
>
>
>     /**
>
>      * Record the fact that a servlet context attribute was replaced.
>
>      *
>
>      * @param event The servlet context attribute event
>
>      */
>
>     public void attributeReplaced(ServletContextAttributeEvent event) {
>
>
>
>       log("attributeReplaced('" + event.getName() + "', '" +
>
>           event.getValue() + "')");
>
>
>
>     }
>
>
>
>
>
>     /**
>
>      * Record the fact that this web application has been destroyed.
>
>      *
>
>      * @param event The servlet context event
>
>      */
>
>     public void contextDestroyed(ServletContextEvent event) {
>
>
>
>       log("contextDestroyed()");
>
>       this.context = null;
>
>
>
>     }
>
>
>
>
>
>     /**
>
>      * Record the fact that this web application has been initialized.
>
>      *
>
>      * @param event The servlet context event
>
>      */
>
>     public void contextInitialized(ServletContextEvent event) {
>
>
>
>       this.context = event.getServletContext();
>
>       log("contextInitialized()");
>
>
>
>     }
>
>
>
>
>
>     // -------------------------------------------------------- Private
> Methods
>
>
>
>
>
>     /**
>
>      * Log a message to the servlet context application log.
>
>      *
>
>      * @param message Message to be logged
>
>      */
>
>     private void log(String message) {
>
>
>
>       if (context != null)
>
>           context.log("ContextListener: " + message);
>
>       else
>
>           System.out.println("ContextListener: " + message);
>
>
>
>     }
>
>
>
>
>
>     /**
>
>      * Log a message and associated exception to the servlet context
>
>      * application log.
>
>      *
>
>      * @param message Message to be logged
>
>      * @param throwable Exception to be logged
>
>      */
>
>     private void log(String message, Throwable throwable) {
>
>
>
>             if (context != null)
>
>                 context.log("ContextListener: " + message, throwable);
>
>             else {
>
>                 System.out.println("ContextListener: " + message);
>
>                 throwable.printStackTrace(System.out);
>
>             }
>
>
>
>     }
>
>
>
> }
>
>
>
> I also added a Listener entry in the application web.xml:
>
>             <listener>
>
>
> <listener-class>starters.ContextServletsTest</listener-class>
>
>       </listener>
>
>
>
> For some reason its not working and I can't figure it out.
>
> Apperently I did every thing as required. Yet it doesn't function at all.
>
> Thanks in advance,
>
>
>
> Asaf Lahav
>
>
>
> VP R&D, Prima Grid LTD.
>
>
>
> Cellular:  972-54-4717955
>
>
>
> Phone:   972-3-6540255
>
>
>
> Fax:       972-3-6540254
>
>
>
>
>
>
>
> -----Original Message-----
> From: Parsons Technical Services [mailto:parsonstechnical@earthlink.net]
> Sent: Monday, May 15, 2006 11:45 PM
> To: Tomcat Users List
> Subject: Re: Run class in the start up of Tomcat
>
>
>
> Are you wanting to start a servlet or load a class?
>
>
>
> You can load a servlet at the application level.
>
> load-on-startup in the servlet class element in the web.xml of the app.
>
>
>
>   <servlet>
>
>      <servlet-name>Scored</servlet-name>
>
>      <servlet-class>srm.Scored</servlet-class>
>
>      <load-on-startup>1</load-on-startup>
>
>     </servlet>
>
>
>
> The number indicates the order that the servlet is loaded.
>
>
>
> As for a class you will need to look into the class loader for Tomcat.
>
>
>
> http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html
>
>
>
> Doug
>
>
>
>
>
> ----- Original Message -----
>
> From: "Juanjo Cuadrado" <jj...@gmail.com>
>
> To: <us...@tomcat.apache.org>
>
> Sent: Monday, May 15, 2006 5:08 PM
>
> Subject: Run class in the start up of Tomcat
>
>
>
>
>
> Hi,
>
>
>
>    I'm trying to run a class in startup of Tomcat. I think that this was
>
> possible in others versions of Tomcat (I just started with Tomcat 5). I
>
> think that it was a property in someone element of server.xml that allowed
>
> this.
>
>
>
>     Anyone can help me? I hope that yes ;) tx
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
>
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>

RE: Run class in the start up of Tomcat

Posted by Asaf Lahav <as...@primagrid.com>.
Wouldn't it be better to develop a ServletContextListener servlet?

 

Anyhow, 

I did give it a try and I attempt to develop a ServletContextListener
servlet.

This is the code I'm using (took it from tomcat servlet samples):

/**

 * 

 */

package starters;

 

import javax.servlet.ServletContext;

import javax.servlet.ServletContextAttributeEvent;

import javax.servlet.ServletContextAttributeListener;

import javax.servlet.ServletContextEvent;

import javax.servlet.ServletContextListener;

 

public class ContextServletsTest implements ServletContextAttributeListener,

            ServletContextListener {

 

       /**

     * The servlet context with which we are associated.

     */

    private ServletContext context = null;

 

 

    // --------------------------------------------------------- Public
Methods

 

 

    /**

     * Record the fact that a servlet context attribute was added.

     *

     * @param event The servlet context attribute event

     */

    public void attributeAdded(ServletContextAttributeEvent event) {

 

      log("attributeAdded('" + event.getName() + "', '" +

          event.getValue() + "')");

 

    }

 

 

    /**

     * Record the fact that a servlet context attribute was removed.

     *

     * @param event The servlet context attribute event

     */

    public void attributeRemoved(ServletContextAttributeEvent event) {

 

      log("attributeRemoved('" + event.getName() + "', '" +

          event.getValue() + "')");

 

    }

 

 

    /**

     * Record the fact that a servlet context attribute was replaced.

     *

     * @param event The servlet context attribute event

     */

    public void attributeReplaced(ServletContextAttributeEvent event) {

 

      log("attributeReplaced('" + event.getName() + "', '" +

          event.getValue() + "')");

 

    }

 

 

    /**

     * Record the fact that this web application has been destroyed.

     *

     * @param event The servlet context event

     */

    public void contextDestroyed(ServletContextEvent event) {

 

      log("contextDestroyed()");

      this.context = null;

 

    }

 

 

    /**

     * Record the fact that this web application has been initialized.

     *

     * @param event The servlet context event

     */

    public void contextInitialized(ServletContextEvent event) {

 

      this.context = event.getServletContext();

      log("contextInitialized()");

 

    }

 

 

    // -------------------------------------------------------- Private
Methods

 

 

    /**

     * Log a message to the servlet context application log.

     *

     * @param message Message to be logged

     */

    private void log(String message) {

 

      if (context != null)

          context.log("ContextListener: " + message);

      else

          System.out.println("ContextListener: " + message);

 

    }

 

 

    /**

     * Log a message and associated exception to the servlet context

     * application log.

     *

     * @param message Message to be logged

     * @param throwable Exception to be logged

     */

    private void log(String message, Throwable throwable) {

      

            if (context != null)

                context.log("ContextListener: " + message, throwable);

            else {

                System.out.println("ContextListener: " + message);

                throwable.printStackTrace(System.out);

            }

 

    }

 

} 

 

I also added a Listener entry in the application web.xml:

            <listener>

 
<listener-class>starters.ContextServletsTest</listener-class>

      </listener>

 

For some reason its not working and I can't figure it out.

Apperently I did every thing as required. Yet it doesn't function at all.

Thanks in advance,

 

Asaf Lahav

 

VP R&D, Prima Grid LTD.

 

Cellular:  972-54-4717955

 

Phone:   972-3-6540255

 

Fax:       972-3-6540254

 

 

 

-----Original Message-----
From: Parsons Technical Services [mailto:parsonstechnical@earthlink.net] 
Sent: Monday, May 15, 2006 11:45 PM
To: Tomcat Users List
Subject: Re: Run class in the start up of Tomcat

 

Are you wanting to start a servlet or load a class?

 

You can load a servlet at the application level.

load-on-startup in the servlet class element in the web.xml of the app.

 

  <servlet>

     <servlet-name>Scored</servlet-name>

     <servlet-class>srm.Scored</servlet-class>

     <load-on-startup>1</load-on-startup>

    </servlet>

 

The number indicates the order that the servlet is loaded.

 

As for a class you will need to look into the class loader for Tomcat.

 

http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html

 

Doug

 

 

----- Original Message ----- 

From: "Juanjo Cuadrado" <jj...@gmail.com>

To: <us...@tomcat.apache.org>

Sent: Monday, May 15, 2006 5:08 PM

Subject: Run class in the start up of Tomcat

 

 

Hi,

 

   I'm trying to run a class in startup of Tomcat. I think that this was

possible in others versions of Tomcat (I just started with Tomcat 5). I

think that it was a property in someone element of server.xml that allowed

this.

 

    Anyone can help me? I hope that yes ;) tx

 

 

 

---------------------------------------------------------------------

To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org

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


Re: Run class in the start up of Tomcat

Posted by Parsons Technical Services <pa...@earthlink.net>.
Are you wanting to start a servlet or load a class?

You can load a servlet at the application level.
load-on-startup in the servlet class element in the web.xml of the app.

  <servlet>
     <servlet-name>Scored</servlet-name>
     <servlet-class>srm.Scored</servlet-class>
     <load-on-startup>1</load-on-startup>
    </servlet>

The number indicates the order that the servlet is loaded.

As for a class you will need to look into the class loader for Tomcat.

http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html

Doug


----- Original Message ----- 
From: "Juanjo Cuadrado" <jj...@gmail.com>
To: <us...@tomcat.apache.org>
Sent: Monday, May 15, 2006 5:08 PM
Subject: Run class in the start up of Tomcat


Hi,

   I'm trying to run a class in startup of Tomcat. I think that this was
possible in others versions of Tomcat (I just started with Tomcat 5). I
think that it was a property in someone element of server.xml that allowed
this.

    Anyone can help me? I hope that yes ;) tx



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