-1

I have created one java project which has one Main class. So I am running this Java Project using this Main class main method . But now my requirement is changed that I have to create the EJB of this project, and deployable artifact will be EAR. So still in the search of that how i will run this main method on the deployment of this EAR in Websphere.

Just want to summarize that I want to execute main method in EJB on the deployment of EAR in WebSphere, searched a lot try one or two methods but still searching for some good way.

Girish
  • 1,717
  • 1
  • 18
  • 30

2 Answers2

1

From your question and comments it is not entirely clear to me if you fully understand how EJBs work (i.e. their lifecycle, how they get called, etc.). If you haven't done so, I recommend reading a Java EE tutorial, e.g. this one from Oracle.

Once you have an overview how things work, have a look here and choose the way which fits best for your case.

Common to all ways is that you cannot have a main method as before, but you have to convert it to a normal public method of your EJB which will get called at startup.

Since you are using and EAR anyway, you can also package a WAR inside the EAR along your EJB, and then use the ContextListener method described in my link.

But also nowadays there is almost no need to have an EAR. You could package everything in a WAR. See here: Why use an ear instead of a war?

Community
  • 1
  • 1
jhyot
  • 3,733
  • 1
  • 27
  • 44
0

As far as I know, if you're on Java EE 6 and you want your EJBs methods to be called in a scheduled manner, you can make a scheduler EJB by annotating it with @Schedule, inject your EJBs in it and make the scheduled method to call your injected EJBs methods. If that's not the case and you want to call them on demand, you need a client like a Servlet in which you inject them.

DSF
  • 804
  • 7
  • 15
  • I don't want to make the scheduled EJBs, I just want to create the listeners So I will be able to consume the message which are coming on page – Girish Oct 28 '15 at 18:25
  • If you're trying to consume messages pun on a JMS queue, you need to create a MDB EJB and you can find plenty tutorials on google on how to do that :) – DSF Oct 28 '15 at 18:29
  • Actually from main I want to start the execution of My Project, and this main method is inside the EJB and then main calls the function which is responsible for creating the connection with some API and then I have created the thread pool to maintain the listener over that to read the messages. So main thing I have concern about is when my EJB is deployed then how websphere will invoke my main method – Girish Oct 28 '15 at 18:36