Since J2EE Servlet v2.3, there's an easy, standard way to hook in your initialization at deployment time. You simply write a [http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextListener.html 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 [http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextEvent.html ServletContextEvent] containing the ServletContext of your webApp.

The [http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContext.html 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);
        }
    }