Hi Vineesh,

Thats simple. Just check the link below for information on 
ServletContextListener. This is just according to the Servlet spec with tomcat 
its just as easy:

http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextListener.html

Sample code:

ApplicationListener.java

package xxx;

import javax.servlet.ServletContextListener;
import javax.servlet.ServletContextEvent;

public class ApplicationListener implements ServletContextListener {
  public void contextInitialized(ServletContextEvent cse) {
    System.out.println("Application initialized");
    //call any other class here
  }
  public void contextDestroyed(ServletContextEvent cse) {
    System.out.println("Application shut down");
    //do any clean up here
  }
}

Add this class to web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 
2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd";>
 <web-app>
  <listener>
   <listener-class>xxx.ApplicationListener</listener-class>
  </listener>
</web-app>

Add the relevant classes to web-inf/classes, start your app and its all done.

Thanks,
Prabhu S

-----Original Message-----
From: vineesh kumar [mailto:[EMAIL PROTECTED]
Sent: Friday, December 09, 2005 11:07 AM
To: Tomcat Users List; [EMAIL PROTECTED]
Subject: How to load a class when tomcat starts


Hi all,

  I need to load a java class when tomcat starts, which will
initializes some configuration files and so i can use the fields in
the class throught the environment.How can i do this.?
Actually I am working on a distributed application, so the
configuration files may change frequently but once the system is
initialized it will not change until shut down.
regards
 vineesh

This e-mail and any files transmitted with it are for the sole use of the 
intended recipient(s) and may contain confidential and privileged information.
If you are not the intended recipient, please contact the sender by reply 
e-mail and destroy all copies of the original message.
Any unauthorized review, use, disclosure, dissemination, forwarding, printing 
or copying of this email or any action taken in reliance on this e-mail is 
strictly
prohibited and may be unlawful.

  Visit us at http://www.cognizant.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to