This is probably a silly question, but I have a need to start a class at the deployment time of an ear file, at the moment it is "inserted" into the J2EE server (JBoss but this is not important).
What would I need to put in the ejb-jar.xml file (or any other file) in order to achieve this.
Any help is welcome.
I think the most recent J2EE spec has some coverage for startup and shutdown events, but I'm not familiar with it, and it may not be widely implemented yet. It's definitely worth looking into, of course. Most appservers have had a proprietary way of invoking startup classes for awhile, but, of course, there's a portability problem.
One way to approach it within the older spec is to create a servlet that invokes your class. If the instances will be multi-threaded, there may be special configuration parameters necessary to allow the servlet to create threads.
Once you have the servlet ready, you set it up to "load-on-startup" -- in web.xml:
The number in "load-on-startup" is a sequence -- you can use 1, 2, etc.
This will invoke the servlet (and your class) when the application starts. If need be, you can set the application itself to auto-start in server.xml:
<application auto-start="true|false" ...>
This will make sure your app starts up when the application server does.