This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
There is nothing in the J2EE spec. to do this, the servlet spec. is the only spec. which has anything to handle startup events. There are vendor-specific solutions: WebSphere Express has startup beans, Weblogic too (as far as I remember), JBoss has a set deploy order which you can use (sars first) etc.
There is a complex way to do it which is spec. compliant. You configure a webapp with a servlet, which is started when it is deployed. It fires off a message to an MDB. If the MDB is deployed (along with the rest of your EJB layer) it will pick up the message and do your startup tasks. If it isn't deployed, the message sits on a queue till it is. This frees you from needing to make sure your webapp starts first, is spec. compliant, but is a fairly heavyweight way of doing it.
Write a stateless session bean and place the initialization code in its ejbCreate method. Use the vendor's DD to set the max number of beans in the pool to 1. When the EJB Server starts up, the bean instance will be created and its ejbCreate method will be invoked.