aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB project startup class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB project startup class" Watch "EJB project startup class" New topic
Author

EJB project startup class

Ricardo Estafan
Ranch Hand

Joined: Mar 29, 2004
Posts: 84
Hi all,

is there a convenient way to use a startup class in an ejb project?
I want to initialize log4j etc. like i would in a servlet using a ServletContextListener and respond to contextInitialized.

However in an ejb application offcourse one cannot use the ServletContextListener in this case.

Does anyone know how to deal with this issue (dealing with certain issues e.g. initialization on application startup)?

Thanks a lot!!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
I have not tried this, but it may work.

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.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10268
    
169

MBean can be used for doing startup of applications.
Have a look at the following:
http://personal.vsnl.com/sureshms/jboss.html

Look at the Writing a Startup Class section


[My Blog] [JavaRanch Journal]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by jaikiran pai:
MBean can be used for doing startup of applications.
Have a look at the following:
http://personal.vsnl.com/sureshms/jboss.html

Look at the Writing a Startup Class section


Of course, this is a JBoss only solution.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10268
    
169

Ya, you are right. This is a jboss specific solution
 
 
subject: EJB project startup class