Discussions

EJB programming & troubleshooting: Accessing a EJB deployed in websphere 5.1

  1. Accessing a EJB deployed in websphere 5.1 through remote client its an copnsole based application.

     i am writing an application by placing naming.jar and namingclient.jar files in my classpath and my application is


    public class SesClient1 {
       public static void main(String[] args) {
           try {
               Context initial = getInitialContext();
               Object obj= initial.lookup("ses");
               SesHome home =(SesHome)obj;
               SesRemote h = home.create();
    String res = h.BusinessMethod1(" Client1 ");
    System.in.read();
    System.in.read();
               System.out.println("name set by client 1");
            res= h.BusinessMethod2();
            System.out.println("name returned by BusinessMethod2" +res);
           }catch(Exception e){ System.out.println(e);}
       }
      static public Context getInitialContext() throws Exception
      {
        try{
          Hashtable h = new Hashtable();
          h.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
          h.put(Context.PROVIDER_URL, "iiop://localhost:9080");
          h.put(Context.SECURITY_PRINCIPAL,"admin");
          h.put(Context.SECURITY_CREDENTIALS,"admin");
          Context ctxt=new InitialContext(h);

        return(ctxt);
        }catch(Exception e){System.out.println(" "+e);}
        return(null);
      }
    }

     i am getting a exaception the exception is

    Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/CORBA/iiop/Ob
    jectURL
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Class.java:140)
            at com.ibm.websphere.naming.WsnInitialContextFactory.init_implClassCtor(
    WsnInitialContextFactory.java:170)
            at com.ibm.websphere.naming.WsnInitialContextFactory.getInitialContext(W
    snInitialContextFactory.java:110)
            at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
    62)
            at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243
    )
            at javax.naming.InitialContext.init(InitialContext.java:219)
            at javax.naming.InitialContext.<init>(InitialContext.java:195)
            at SesClient1.getInitialContext(SesClient1.java:27)
            at SesClient1.main(SesClient1.java:7)


    please help me its very urgent
  2. where is your cast???[ Go to top ]

    SesHome home =(SesHome)obj
    home = (SesHome)PortableRemoteObject.narrow(obj,SesHome.class);

    Try this dude!!!
  3. you need to use an IBM JRE