My app has a bit of expensive setup to do when it first starts up. It appears that as soon as I copy the WAR file in webapps, the log file says "Deploying web application archive Navaid.jar", but it doesn't actually run anything until I hit the URL. I'd rather than have the first person to hit the url endure the wait time for this start up. Is there an "onDeploy" method I could use or something to do that processing, or should I just have ant copy the file, wait a few seconds, and then wget the url?
views:
32answers:
2
A:
You can specify a couple of Servlets to load on startup in your web.xml
file. They can then call various parts of your app to make sure they are primed.
Aaron Digulla
2009-10-28 15:58:20
How does one do that?
Paul Tomblin
2009-10-28 16:22:38
+1
A:
Implement a class with the ServletContextListener
interface, then declare it as a listener in your web.xml:
<listener>
<listener-class> ...your class here... </listener-class>
</listener>
Your class will get called on startup (& on shutdown).
Keith Randall
2009-10-28 17:03:37
Awesome, that works. Now I just have to figure out how to get the other servlets to block responding until this is done, but that's another question.
Paul Tomblin
2009-10-28 18:28:28
No servlet will be invoked by the container until the call to your ServletContextListener is completed. See http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContextListener.html
Keith Randall
2009-10-28 20:51:13