When the SimplePOJO is packaged in the same jar along with SimpleBean, I
don't know why you want to look up the SimpleBean from the SimplePOJO.
But any way, yes, you need a ejb-jar.xml like this to do a EJB look up
from a POJO. Here is an example: (This works as long as SimplePOJO is
called in the context of SimpleBean, for the ejb-loca-ref is defined in
the env context of SimpleBean only.
<ejb-jar version="3.0" xmlns="
http://java.sun.com/xml/ns/javaee">
<enterprise-beans>
<session>
<ejbname>SimpleBean</ejbname>
<ejb-local-ref>
<ejb-ref-name>ejb/SimpleBean</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>packagename.SimpleLocal</local>
<ejb-link>SimpleBean</ejb-link>
</ejb-local-ref>
</session>
</enterprise-beans>
<ejb-jar>
Thanks,
Sahoo
angelogeminiani wrote:
> Hi,
> I'm newbie in EJB3 and I've been struggling for 2 days trying to do a simple
> JNDI lookup.
> I have a stateless session bean (EJB 3.0) in an EJB Module project, and a
> Web Project.
> The two projects are packaged in a Enterprise Application project.
>
> In my EJB Module I have a POJO that need lookup to ebj object (SimpleBean).
> SimpleBean and SimplePOJO are in same EJB Module.
>
> The EJB:
>
> @Local
> public interface SimpleLocal{
> ...
> }
>
> @Stateless()
> public class SimpleBean
> implements SimpleLocal{
> ...
> }
>
> The POJO:
>
> public class SimplePOJO {
>
> // .ctor
> public SimplePOJO (){
> Context c = new InitialContext();
> SimpleLocal myBean =
> (SimpleBean)c.lookup("java:comp/env/ejb/SimpleBean");
> }
>
> }
>
> I tried use my SimpleBean from a servlet using annotation @EJB and here
> works fine.
> But in my SimplePOJO constructor I get a javax.naming.NameNotFoundException.
>
> Is there something wrong in my code?
> Do I need a .xml descriptor?
>
> Thank you,
> Angelo
>
>