Just set up a listener and specify a description in Web. Xml.
Web. XML is actually a description file that will be read when Tomcat starts, such as when accessing the server home page can be specified in the inside, there is a corresponding tag. Here's an explanation: http://blog.chinaunix.net/uid-20399471-id-1687965.html
To implement this listener interface:
1 Public classMyservletcontextlistenerImplementsServletcontextlistener {2 3 @Override4 Public voidcontextdestroyed (servletcontextevent arg0) {5 //Notification that, the servlet context is on to being shut down. 6 }7 8 @Override9 Public voidcontextinitialized (servletcontextevent arg0) {Ten //Do all the tasks, the need to perform just after the server starts One A //Notification The Web application initialization process is starting - } - the}
Then write the listener tag in Web. XML and add the Listener class:
Mytestlistener replace the class name that implements the Servletcontextlistener interface yourself
< Listener > < Listener-class > [Package]. Mytestlistener</listener-class> </listener >
References
Http://stackoverflow.com/questions/13819773/how-to-run-specific-java-code-on-tomcat-start-or-on-application-deploy
Http://stackoverflow.com/questions/158336/is-there-a-way-to-run-a-method-class-only-on-tomcat-startup
http://crunchify.com/how-to-run-java-program-automatically-on-tomcat-startup/
Http://blog.sina.com.cn/s/blog_6ea90e4b0100ny3t.html
How to run a Java class when Tomcat is started