Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB project startup class

 
Ricardo Estafan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya, you are right. This is a jboss specific solution
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic