title: @EJB injection fails but JNDI lookup works in web service class in Glassfish
body: <p>I have a @WebService class that injects an @EJB.  The EJB is packaged in a .jar file which is in the same .war file as the web service classes.  The @EJB injection always fails, but I can do a JNDI lookup on the EJB.  I've tried making the EJB and its interface @Remote, but that didn't matter.  Injection still fails and JNDI lookup still works.</p>
  
  <p>I'm using a version 3.0 web.xml.  There's no ejb deployment descriptor in the ejb.jar file, but that is not suppose to matter in EJB 3.1.</p>
  
  <p>An I missing something or is this a bug in Glassfish?</p>
  
  <p>Here's my code.</p>
  
  <p>EJB class and interface packaged in a .jar in the .war file:</p>
  
  <pre><code>//@Remote
  public interface ReportServiceI {
  
      public String testAlive();
  }
  
  @Stateless
  //@Remote (ReportServiceI.class)
  public class ReportService implements ReportServiceI {...}
  </code></pre>
  
  <p>Web service class:</p>
  
  <pre><code>@WebService(
    targetNamespace = "http://www.reps.corp.com/services/reports/ReportService", 
    portName="ReportPort",
    serviceName="ReportService", 
    endpointInterface="com.corp.reps.reports.ws.server.ReportServiceWSI")
  
  public class ReportServiceWS implements ReportServiceWSI {
  
    public static Logger logger = Logger.getLogger(ReportServiceWS.class);
  
  //  These all fail
  //  @EJB
  //  @EJB(beanInterface=ReportServiceI.class)
  //  @EJB(lookup="java:global/repsreports/ReportService")
    ReportServiceI reportService;
  
    public String testAlive() {
  
      //  this works
      try {
        InitialContext context = new InitialContext();
        reportService = (ReportServiceI)context.lookup("java:global/repsreports/ReportService");
      }
      catch (NamingException ex) {
        logger.error(ex);
  
        return "InitialContext.lookup() failed.";
      }
  </code></pre>