Please clarify your question. What do you mean by "launching any EJB" ?
Well, I'll try to clarify my question.
I've an MBean, launched by dispatcher, which every minute verifies the hour and, in some specific moments, calls an EJB.
I've developed an Entity Bean to access the database, and this EJB is controlled by the corresponding Session Bean. My problem is that I don't know how to launch this Session Bean from the MBean, how to create a Session Bean object in the MBean to access, by the Entity Bean, to the database.
I've tried to do this of many forms. Sometimes, I obtain a NamingException "not bound", using the BeanManager class defined by sun in Duke'sBank example. If I use this source code directly, I obtain an java.lang.reflect.UndeclaredThrowableException. And this code only tries to obtain a home interface of this EJB!!
I think the problem is around contexts, because I'm calling an EJB from an MBean, instead of calling from a Servlet. But I don't know how to solve it!
If somebody has any suggestion, tell me it, please.
There's nothing different about invoking an EJB from an MBean compared to invoking an EJB from a standalone client. The same API calls apply and the behavior is the same.
Naming exception indicates you're using the wrong lookup name trying to get to the home proxy. Use the name in the global name space (MBeans don't have a private ENC and private references like EJBs).
How can I do it?
I think if you look in the jmx-console under JNDIView you should be able to get the global JNDI names of your EJB's
There are multiple options here.
1. You could bundle them all into a EAR (SAR + JAR) so it will be loaded as one single entity.
2. As Juha pointed out, its no different from calling it from a standalone client Vs. servlet Vs. MBean. All you need to do is get the InitialContext and lookup your EJB JNDI. You will need to get your Home and Remote interfaces in ur SAR(ofcourse!!).