java - Is there a way to run a method/class only on Tomcat/Wildfly/Glassfish startup? -
i need remove temp files on tomcat startup, pass folder contains temp files in applicationcontext.xml.
is there way run method/class on tomcat startup?
you write servletcontextlistener
calls method contextinitialized()
method. attach listener webapp in web.xml, e.g.
<listener> <listener-class>my.listener</listener-class> </listener>
and
package my; public class listener implements javax.servlet.servletcontextlistener { public void contextinitialized(servletcontext context) { myotherclass.callme(); } }
strictly speaking, run once on webapp startup, rather tomcat startup, may amount same thing.
Comments
Post a Comment