0 Replies Latest reply: Apr 18, 2007 12:55 AM by 807606 RSS

    Need a Help to Run the EJB client

    807606
      Hello Friends,

      I'm using EJB3.0. while running my client side bean I got a Exception like this " javax.naming.NameNotFoundException: maheshwaran.count not bound." I'm new to EJB so i couldn't find specifically what is the mistake in my files.

      I created the following files. It are listed below

      FileName: count.java
      ************************



      "package maheshwaran;

      public interface count {

      public int count();

      public void set(int val);

      public void remove();

      } "


      FileName2 : countBean.java
      *******************************


      "package maheshwaran;
      import javax.ejb.*;
      import javax.interceptor.Interceptors;

      @Stateful
      @Remote(count.class)
      @Interceptors(countCallBacks.class)

      public class countBean implements count{

      private int val;

      public int count(){
      System.out.println("count()");
      return ++val;
      }

      public void set(int val){
      this.val=val;
      System.out.println("set()");
      }

      @Remove

      public void remove(){

      System.out.println("remove()");

      }
      } "


      FileName3: countCallBacks.java
      ************************************


      " package maheshwaran;

      import javax.annotation.PostConstruct;
      import javax.annotation.PreDestroy;
      import javax.ejb.*;
      import javax.interceptor.InvocationContext;


      public class countCallBacks {

      @PostConstruct
      public void construct(InvocationContext ctx){

      System.out.println("cb:construct()");
      }

      @PostActivate
      public void activate(InvocationContext ctx){
      System.out.println("cb:activate()");
      }

      @PrePassivate

      public void passivate(InvocationContext ctx){
      System.out.println("cb:passivate()");
      }

      @PreDestroy

      public void destroy(){
      System.out.println("cb:destroy()");
      }

      }"

      The client side class is following: countClient.java
      ********************************************************


      "package maheshwaran;

      import javax.naming.*;

      public class countClient {

      public static final int noofClients=3;

      public static void main(String args[]){

      try{

      Context ctx=new InitialContext(System.getProperties());
      count count[]=new count[noofClients];

      int countval=0;

      System.out.println("Instatntiating Beans");

      for(int i=0;i<noofClients;i++){

      count=(count) ctx.lookup(count.class.getName());

      count.set(countval);
      countval=count.count();
      System.out.println(countval);
      Thread.sleep(100);

      }

      System.out.println("Calling count on Beans");

      for(int i=0;i<noofClients;i++){

      countval=count.count();
      System.out.println(countval);
      count.remove();
      Thread.sleep(50);
      }


      }catch(Exception e){e.printStackTrace();}

      }

      } "


      The Deployment Descriptor file is following: ejb-jar.xml
      ************************************************************

      "><?xml version="1.0" encoding="UTF-8?>
      <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.0"
      xmlns:xsi="http://www.w3.org/2001/XMLschema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">


      <description>Stateful Session Bean Example</description>
      <display-name>Stateful Session Bean Example</display-name>
      <enterprise-beans>
      <session>
      <ejb-name>countBean</ejb-name>
      <business-remote>maheshwaran_dd.count</business-remote>
      </business-remote>
      <ejb-class>maheshwaran_dd.countBean</ejb-class>
      <session-type>Stateful</session-type>
      <transaction-type>Container</transaction-type>
      </session>
      </enterprise-beans>
      <interceptors>
      <interceptor>
      <interceptor-class>maheshwaran_dd.countCallBacks</interceptor-class>
      <post-construct>
      <lifecycle-callback-method>construct</lifecycle-clallback-method>
      </post-construct>
      <post-activate>
      <lifecycle-callback-method>activate</lifecycle-callback-method>
      </post-activate>
      <pre-passivate>
      <lifecycle-callback-method>passivate</lifecycle-callback-method>
      </pre-passivate>
      </interceptor>
      </interceptors>

      <assembly-descriptor>
      <interceptor-binding>
      <ejb-name>countBean</ejb-name>
      <interceptor-class>maheshwaran_dd.countCallBacks</interceptor-class>
      </interceptor-binding>
      </assembly-descriptor>
      </ejb-jar> "

      please help me to rectify this problem.

      Thanks & regards,
      Maheshwaran Devaraj