0
votes

I have a project which at the end will be packaging to an ear file, this ear file contains two eclipse project, one for EJB and it will be packaging to a jar file and another project is a web project, which will be packaging to a war file.

a serverlet is be dev in the war file and all EJB in the jar file.

I know we can use JNDI to ref EJB, but how can I use dependence inject to inject the EJB to my war file?

1

1 Answers

2
votes

It should be sufficient to just annotate it with @EJB in your servlet class:

public class MyServlet
extends HttpServlet {
    @EJB
    private ApplicationLogicEJB logicEJB;

    // ...
}

If your .ear file has an application.xml, that file must contain a <module> element for the EJB .jar file as well as a <module> for the .war file.