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

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -