I've created a NetBeans Enterprise application which consists of an ear that wraps an ejb (jar) project and a web (war) project.
I have a servlet in my web project and I want to use one of the EJBs from the ejb project in it.
@WebServlet(name = "Shop", urlPatterns = {"/ajax/add_to_cart"})
public class ShoppingCartServlet extends HttpServlet {
@EJB
ShoppingCartFacade shoppingCartFacade
I am getting an error in NetBeans - "cannot find symbol" for the ShoppingCartFacade. Netbeans can't automatically find the package for ShoppingCartFacade even though it is in the "sibling" ejb project. If I start manually typing in the package name in the Servlet, ie.
import com.myproject....
I can see that the only packages visible are the ones in the web project itself, ie.
com.myproject.web.my_web_related_package
is visible
whereas
com.myproject.ejb.my_ejb_related_package
is not visible
Surely it must be straightforward to inject an EJB into a web project as the whole point of having separate ejb and web projects is so that business logic can be placed in ejbs and called from web resources such as servlet.
So how am I supposed to use an EJB in a web (war) application?
I had to explicity declare the ejb project as a dependency of the web project. It seems this is done automatically if it's a regular NetBeans Enterprise Application but not if it's a Maven Enterprise Application, which it was in my case.