My Web App will be deployed as a WAR package in a Jetty instance. It needs to perform a lot of caching before serving requests. How do I call the caching method before anything else? is the a static void main() in the web app standard?
+1
A:
A standard (old) way is to code a Servlet which takes care of initialization stuff in its init()
method. You force it to be initialized at application start by adding a load-on-startup
positive value in your web.xml
<servlet>
<servlet-name>myinit</servlet-name>
<servlet-class>com.example.MyInitServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
Today it's more usual to have a bean container like Spring, which takes care of this kind of things (instantiating services objects, preloading cacheable sharable data, etc).
Note: this recipe is for webapps in general, not specific to Jetty.
leonbloy
2010-05-06 02:21:51
I like this solution because I can use it with any web app server.I will need a dummy servlet for that though. Is there a way to perform such initialization without implementing a servlet? Is there a static void main() for web apps?
Gatis
2010-05-06 03:17:12
It seems adding a ServletContextListener is all that I want.
Gatis
2010-05-06 10:21:32