EJB3 local bean access in servlet using glassfish
I was trying out Glassfish.
I made a separate ear with a stateless bean and a war with a servlet that accesses the stateless bean using @EJB injection. I deployed the ejb jar file and also the servlet war file. It did not work. The error was that the servlet did not find the ejb.
Reading the glassfish docs I came across this question in the glassfish faq.
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
Question: I have an EJB with a Local interface. Can I access it from a web component in a different application?
Answer: No, not in our implementation. The EJB spec only requires local ejb access from within the same application in the same JVM.
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
Actually that makes a lot of sense.
All I needed to do was to have an ear file with both the war and ear as modules. That way the local EJB could be found by the servlet.
Since the servlet needed to access the local interface I also packaged the interface in WEB-INF/lib/ejbinterfaces.jar folder.