can someone tell me how to call EJB from a java client application?
The easiest way is to provide a http gateway using a servlet that runs on the same app server as the EJBs and acts as the bridge between your client code(which I assume is a desktop application) and the EJBs.
is this method the best one?
and do you have another method about it?
You can get a direct handle to the EJB from a application client. You just need to specify a few additional parameters in you InitialContext object. These are different for each app server. What server are you trying to talk with, maybe I have an example for you? Anyway, once you make the connection you do the lookup like normal, you have to narrow the returned object as it will be an RMI object that you get back, then you just use it like normal.
It actually depend upon the type of Java application you are using. If it's a web application in JSP etc, it's better
to talk to a gateway Servlet and let the servlet talk to the
EJB. Then Java app will talk to Servlet in HTTP mode and Servlet and EJB will talk in RMI. That will be beneficial in places with firewalls etc.
But if the Java application is nothing but a non-GUI applications, it's better to cut the servlet layer and talk directly to EJB by getting the Home from JNDI and creating the bean.
Hope this helps.