3

We're thinking of building a client/server application where the server side would be an EAR application with some Session Beans exposing the API. We would like to know if there's something like the ServletContextListener for the web modules in EJB modules so we can know when the application in the server side is started.

Thanks is advance.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
PaquitoSoft
  • 3,177
  • 6
  • 29
  • 32

3 Answers3

4

In JEE5, no there is no other mechanism. The ServletContextListener is the best, portable, solution.

In JEE6, you can use a Singleton EJB. You can annotate the Singleton EJB with an @Startup, and the EJB will be created at application launch. So, for a "pure EJB" application with no WAR component, this would be the mechanism to do that.

Will Hartung
  • 115,893
  • 19
  • 128
  • 203
2

Will Hartung basically has the correct answer, but there might still be a small piece of the puzzle to add.

An EAR may have multiple EJB and Web modules. Occasionally it might also be needed to know which one starts up first.

Certainty about this can be gotten by using <initialize-in-order>true</initialize-in-order> in the Java EE 6 application.xml file in META-INF dir of your EAR.

The order of the modules listed then determines the startup order and does tell you whether e.g. a particular @Startup annotated Singleton is called when the first or last module is started.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
0

No way I'm aware of. See this related question.

Since you have an EAR, you can use the ServletContextListener.

Community
  • 1
  • 1
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140