Im not an JEE expert but I think that if you are trying to use a Bean ( no matter if it is from a Servlet or another Bean) in another JVM and another container, you can't use Injections, instead you must use JNDI and lookup for the remote interface of the Bean (Passing the required parameters to the getInitialContext(Properties p) method like the IP address of the container where the Bean is deployed).
What I'm not sure if that if you are in another JVM, you are gonna get a compiler error because I suposse the project where you are building your servlet do not have the definition of the remote interface of the bean.
Yes, you absolutely can use @EJB in servlets. In fact, that is the main use case and where EJBs were meant to be invoked from.
I saw someone complain that this was not implemented for some reason, though, in JBoss, or was broken/didn't work. If you are using JBoss that may be what you are seeing. This is definitely not compliant, though. @EJB should work fine in servlets.
I just looked at your code and noticed that you are injecting into a type T2Facade, which is the bean impl class. You should define the variable to be of your interface type (T2FacadeLocal) to use the EJB. (I'm actually surprised you are not getting an exception at deployment-time.)
Mike: you're right, @EJB can't be used in servlets in Jboss 4.2.2. See e.g. the "Getting Started Guide" section 2.1. Thus Jboss is not fully JEE compliant! It took me several days of hair-pulling and wall-kicking to find out.
I have also tried to do a specific JNDI lookup, but have failed so far. Is there any examples of how to do it (preferably portable)? [ April 01, 2008: Message edited by: Per Lindberg ]
Yea, i have the same problem with jboss 4.2.2ga. Also, its call exception, when i try to cast data obtain by using serialization class inside Vector set. 4.2.2 is rake. imho. Found my way in study EJB 3 with Glassfish v2.1 (its full Java EE 5 supported app.server). have fun.