tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anoop kumar V <anoopkum...@gmail.com>
Subject Re: How to load a class when tomcat starts
Date Mon, 26 Dec 2005 06:17:00 GMT
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 <vineeshkumarpv@gmail.com> 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 <anoopkumarv@gmail.com> 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 <rnmixon@qwest.net> 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:vineeshkumarpv@gmail.com]
> > > 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: users-unsubscribe@tomcat.apache.org
> > > For additional commands, e-mail: users-help@tomcat.apache.org
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > > For additional commands, e-mail: users-help@tomcat.apache.org
> > >
> > >
> >
> >
> > --
> > Thanks and best regards,
> > Anoop
> >
> >
>



--
Thanks and best regards,
Anoop

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message