Here is some code that might help you:

import java.io.*;
import java.net.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class InitServlet extends HttpServlet {

    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        System.out.print("Loading classes in the JVM ");
        try{
            Class.forName("com.m2.isr2.Database");
            System.out.print(".");
            Class.forName("com.m2.isr2.platform.ActiveDirectory");
            System.out.print(".");
        } catch (ClassNotFoundException e)
        {
            System.out.println(e);
            e.printStackTrace(System.out);
        }
        System.out.println(" Completed!");
    }

Hope that helps you...
Anoop


On 12/15/05, vineesh kumar <[EMAIL PROTECTED]> wrote:
>
> Dear anoop,
>        Wat i actually need is the same as u hav done, to load a config
> file.
> so i created a GetProperties class, which simlpy read a file and
> initializes some static variables.
> Then i tried to run the application but, the fields are still null.and
> the application is not connecting to the database
> can u just quote the code snippet u had used?
> thanks in advance
> vineesh
> On 12/10/05, Anoop kumar V <[EMAIL PROTECTED]> wrote:
> > The way we have done is to load a servlet during startup (very easy to
> do in
> > web.xml) and through this servlet use Class.forName("classname") to load
> the
> > required classes into memory.
> >
> > The reason we do this is to read a .properties file and store all the
> name
> > value pairs in a hashmap to be retrieved by various classes at run time.
> >
> > Hope that helps,
> > Anoop
> >
> > On 12/10/05, Richard Mixon <[EMAIL PROTECTED]> wrote:
> > >
> > > Vineesh,
> > >
> > > You should probably  use a ServletContextListener . It will give you
> > > control
> > > when the web application starts and when it ends, among otherevents.
> It is
> > > pretty well described in the servlet spec and is pretty simple.
> > >
> > > HTH -Richard
> > >
> > > -----Original Message-----
> > > From: vineesh kumar [mailto:[EMAIL PROTECTED]
> > > Sent: Saturday, December 10, 2005 12:22 AM
> > > To: users@tomcat.apache.org
> > > 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
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> >
> > --
> > Thanks and best regards,
> > Anoop
> >
> >
>



--
Thanks and best regards,
Anoop

Reply via email to