Since J2EE Servlet v2.3, there's an easy, standard way to hook in your initialization at deployment time. You simply write a ServletContextListener and reference it in your web.xml with

  <listener>
    <listener-class>
      com.idiacomputing.startup.StartupServletContextListener
    </listener-class>
  </listener>

ServletContextListener defines two method signatures, contextInitialized and contextDestroyed. Both are passed a ServletContextEvent containing the ServletContext of your webApp.

The ServletContext contains such goodies as the context-param elements of the web.xml file

    private void extractServletContextParameters(Map nameValuePairs, ServletContext servletContext) {
        Enumeration parmEnum = servletContext.getInitParameterNames();
        while (parmEnum.hasMoreElements()) {
            String name = (String) parmEnum.nextElement();
            String value = servletContext.getInitParameter(name);
            nameValuePairs.put(name, value);
        }
    }


See also