How can I load an arbitrary class on startup in Tomcat?
I saw load-on-startup tag for web.xml file, but can I use it and how should I implement my class?
<servlet-name>??</servlet-name>
<servlet-class>??</servlet-class>
<load-on-startup>10</load-on-startup>
Those are meant to specify the loading order for servlets. However, servlets are more meant to control, preprocess and/or postprocess HTTP requests/responses while you sound like to be more looking for a hook on webapp’s startup. In that case, you rather want a
ServletContextListener.If you’re not on Servlet 3.0 yet (and thus can’t use
@WebListener), then you need to manually register it inweb.xmlas follows:See also: