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.
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.