2. Use a "startup servlet", which is basically just a Servlet with its load-on-startup value set to 0. Implement your startup code in the servlet's init() method.
The "better" solution of the two is #1, however it requires a Servlet 2.3 or higher container and, since load order isn't defined in the spec, you should check to make sure your container initializes listeners before servlets.
* WebLogic and Oracle Application Servers in the past initialized Servlets before Listeners. This behavior might have changed with the latest releases.
Joined: Apr 06, 2006
Thanks for answer!
At the time of application server shutdown contextDestroyed() method will be invoked?
I think Servlet only used in Web Container, if you don't use a Web frontier, the problem can't solve. But I'm newbie in J2EE, so all upstairs can ignore my post...
Joined: Jul 18, 2001
Sure, but if you are deploying an EJB solution you are most likely going to deploy as an Enterprise Archive (EAR). Ears support both ejb and war components, very simple to drop in a war for the purpose of providing some startup logic.