Version 2

    Hi,

      I met a problem when I call remote ejb interface in a war.

      1. I create a EJB project, and have a remote interface, and deploy it to JBoss AS7.1.1 successfully

      2. I create a dynamic web project, have a jsf file and a javabean, the javabean call the remote ejb interface. and deploy it to JBossAs7.1.1 server successful

      3.But when I use the browser access the JavaBean's function(and it call the EJB interface), it report a Exception: javax.naming.NameNotFoundException.

     

      Below are the EJB Project and Web Project code:

    1.EJB Project code:

      1)UsersDao.java

    @Stateless

    @Remote(UsersDaoRemote.class)

    public class UsersDao implements UsersDaoRemote{

        @PersistenceContext //这里应用EJB3的IOC,得到EntityManager

        private EntityManager em; //相当于Hibernate的Session

        /**

         * Default constructor.

         */

        public UsersDao() {

            // TODO Auto-generated constructor stub

        }

     

        public String getForUsername(String username)

        {

         xxxx

        }

      2)UsersDaoRemote.java

    @Remote

    public interface UsersDaoRemote{

        public String getForUsername(String username);

    }

     

      2. Web Project JavaBean code:

       public  void loginIn() throws NamingException
        {
             InitialContext  ctx = new InitialContext();

            //String ejbname = "ejb:sms_ejb/UsersDao!com.hxchn.sms.UsersDaoRemote";        //I also try this ,it failed too

            String ejbname = "java:global/sms_ejb/UsersDao!com.hxchn.sms.UsersDaoRemote";       

     

            UsersDaoRemote usersDaoRemote=(UsersDaoRemote)ctx.lookup(ejbname);

      }

     

    3.deploy log:

    10:14:11,378 INFO  [org.jboss.as.jpa] (MSC service thread 1-1) JBAS011403: Stopping Persistence Unit Service 'sms_ejb.jar#sms_ejb'

    10:14:11,410 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015877: Stopped deployment sms_ejb.jar in 37ms

    10:14:11,412 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "sms_ejb.jar"

    10:14:11,424 INFO  [org.jboss.as.jpa] (MSC service thread 1-4) JBAS011401: Read persistence.xml for sms_ejb

    10:14:11,454 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-3) JNDI bindings for session bean named UsersDao in deployment unit deployment "sms_ejb.jar" are as follows:

     

        java:global/sms_ejb/UsersDao!com.hxchn.sms.UsersDaoRemote

        java:app/sms_ejb/UsersDao!com.hxchn.sms.UsersDaoRemote

        java:module/UsersDao!com.hxchn.sms.UsersDaoRemote

        java:jboss/exported/sms_ejb/UsersDao!com.hxchn.sms.UsersDaoRemote

        java:global/sms_ejb/UsersDao

        java:app/sms_ejb/UsersDao

        java:module/UsersDao

     

    10:14:11,516 INFO  [org.jboss.as.jpa] (MSC service thread 1-3) JBAS011402: Starting Persistence Unit Service 'sms_ejb.jar#sms_ejb'

    10:14:11,518 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-3) HHH000204: Processing PersistenceUnitInfo [

        name: sms_ejb

        ...]

    10:14:11,528 INFO  [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-3) HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider

    10:14:11,562 INFO  [org.hibernate.dialect.Dialect] (MSC service thread 1-3) HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect

    10:14:11,565 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-3) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory

    10:14:11,574 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-3) HHH000397: Using ASTQueryTranslatorFactory

    10:14:11,809 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018565: Replaced deployment "sms_ejb.jar" with deployment "sms_ejb.jar"

    10:14:21,890 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015877: Stopped deployment sms_web.war in 14ms

    10:14:21,905 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "sms_web.war"

    10:14:22,061 信息    [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-2) 初始化上下文 '/sms_web' 的 Mojarra 2.1.7-jbossorg-1 (20120227-1401)

    10:14:22,156 INFO  [org.jboss.web] (MSC service thread 1-2) JBAS018210: Registering web context: /sms_web

    10:14:22,388 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018565: Replaced deployment "sms_web.war" with deployment "sms_web.war"

     

    4.Exception:

    HTTP Status 500 -


    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.


    exception

    javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/hxchn/sms/UsersDaoRemote javax.faces.webapp.FacesServlet.service(FacesServlet.java:606) 

    root cause

    1. javax.faces.el.EvaluationException: java.lang.NoClassDefFoundError: com/hxchn/sms/UsersDaoRemote

    javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)

           com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)

            javax.faces.component.UICommand.broadcast(UICommand.java:315)

            javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)

            javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)

            com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)

            com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

            com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)

            javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)

    root cause

    1. java.lang.NoClassDefFoundError: com/hxchn/sms/UsersDaoRemote

            com.hxchn.sms.UserJavaBean.loginIn(UserJavaBean.java:203)

            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

            java.lang.reflect.Method.invoke(Method.java:597)

            org.apache.el.parser.AstValue.invoke(AstValue.java:262)

            org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)

            com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)

    javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)

           com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)

            javax.faces.component.UICommand.broadcast(UICommand.java:315)

            javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)

            javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)

            com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)

            com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

            com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)

            javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)

    root cause

    1. java.lang.ClassNotFoundException: com.hxchn.sms.UsersDaoRemote from [Module "deployment.sms_web.war:main" from Service Module Loader]

            org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)

    org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)

    org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)

    org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)

          org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)

            org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)

            com.hxchn.sms.UserJavaBean.loginIn(UserJavaBean.java:203)

            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

            java.lang.reflect.Method.invoke(Method.java:597)

            org.apache.el.parser.AstValue.invoke(AstValue.java:262)

            org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)

            com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)

    javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)

           com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)

            javax.faces.component.UICommand.broadcast(UICommand.java:315)

            javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)

            javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)

            com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)

            com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

            com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)

            javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)

    JBoss Web/7.0.13.Final