The standard (old) way is to encode a servlet that takes care of initialization in its init() method. You force it to initialize when the application starts, adding a load-on-startup positive value to web.xml
<servlet> <servlet-name>myinit</servlet-name> <servlet-class>com.example.MyInitServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet>
Today, a more common is a bean container such as Spring, which takes care of such things (instance objects, preloading cached data, etc.).
Note: this recipe is for webapps in general, not Jetty.
source share