Search code examples
jsf-2deploymentejb-3.1managed-bean

Can't deploy web app having EJB component injected


software used : 1- GlassFish 3.1.2 2- JDK 6.0 3- Eclipse Juno Service Release 1

whenever I try adding my dynamic web app to GlassFish this exception in pop-up window :

SEVERE: Exception while loading the app : java.lang.IllegalStateException:           
ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
java.lang.RuntimeException: java.lang.NoClassDefFoundError:
Lcoreservlets/bean/NumberService;

I've tried also looking up the EJB component using InitailContext + JNDI in vain, even so it worked from a plain java project .

I tried GlassFish 3.1.1 as well as a last resort but nothing doing .

May you look over my source code and tell me what goes wrong :

for the starters, my POJI :

package coreservlets.bean;
import javax.ejb.*;
@Remote
public interface NumberService {
public double getNumber(double range);
}

secondly EJB POJO :

package coreservlets.bean;
import javax.ejb.*;
@Stateless(mappedName="NumberCreator")
public class NumberServiceBean implements NumberService {
public double getNumber(double range) {
return(Math.random() * range);
}
}

Lastly Managed Bean :

package beans;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import coreservlets.bean.NumberService;
@ManagedBean
@RequestScoped
public class MyBean {

@EJB private NumberService service;
private Double luckyNumber;
public Double getLuckyNumber() {
    luckyNumber = service.getNumber(Math.random() * 100);
    return luckyNumber;
}   
}

Please lend hand sorting out this mess for I've been trying to figure it out for a couple of days so far , Am pretty grateful .


Solution

  • Well, I created the EJb project and the web dynamic project from scratch with the " add project to an EAR " checked, everything is sorted out now . So everyone happened to see my question, I recommend you to follow my answer, because the exception has nothing to do with the code, It might be eclipse-related bug or so .